1

I want to open a "OpenFileDialog", on which we can select only local hard drives (ex. C:\,D:). I want to add restrictions to access network drives. I have used following code but I am able to access the network drive.

Code is given below:

OpenFileDialog dialog = new OpenFileDialog();
            dialog.CustomPlaces.Clear();
            foreach (DriveInfo Drive in DriveInfo.GetDrives())
            {
                if (Drive.DriveType == DriveType.Fixed)
                {
                    dialog.CustomPlaces.Add(Drive.Name);
                }
            }
            dialog.ShowDialog();
halfer
  • 19,824
  • 17
  • 99
  • 186
Amit Kumar
  • 1,059
  • 3
  • 22
  • 43
  • 1
    Just curious - why do you want to restrict network drives? What problem are you trying to solve/prevent? – Gray Jul 11 '13 at 15:25

1 Answers1

3

I don't think this is possible with the built-in OpenfileDialog. Changing the CustomPlaces is just the list of "custom" places you want pinned on the top left. It doesn't limit the places they can go.

I think you'll have to either write a custom dialog (ick!) or do something to validate their selection after they've hit ok.

Tim
  • 14,999
  • 1
  • 45
  • 68