1

How to open specific path or directory via OpenFileDialog By default? For example directory is 'C:\ABC'. And when user click on the upload button then given directory should be open default.

And How to Hide other select option to move with in the directory? Means use can not select another directory. if possible please provide solution.

thanks in advance

naina
  • 63
  • 1
  • 9

2 Answers2

1

Set the InitialDirectory of your dialog to the directory that you would want to open initially when the user open the dialog.

openFileDialog1.InitialDirectory = @"C:\ABC";

As for restrict the user to select file from this location only, I would suggest to create a custom control, and in this control, list out all the files in the directory, and let the user select one.

Yogi
  • 9,174
  • 2
  • 46
  • 61
  • how to lock this directory – naina Jun 01 '16 at 12:22
  • To my understanding it is not possible, and if, at least will not be straightforward. And even if you lock the directory, user can "type" the path of different location. I suggest to use custom control for this. – Yogi Jun 01 '16 at 12:24
0

For specific directory you can use what Yogi suggested

For restriction of navigation, I would suggest you Set the InitialDirectory to your path. If a user selects a another path outside of your path, use the FileOk event to check this and bring the user back to the InitialDirectory

openFileDialog1.InitialDirectory = Path.Combine(Path.GetDirectoryName(Application.StartupPath), "FolderName");

        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {            
                while(Path.GetDirectoryName(openFileDialog1.FileName) != Path.Combine(Path.GetDirectoryName(Application.StartupPath), "FolderName")){

                    MessageBox.Show("Please use the default folder", "Wrong folder", MessageBoxButtons.OK, MessageBoxIcon.Information);
                openFileDialog1.ShowDialog();

            }                       
        }

hope this helps

Patrick
  • 1
  • 2