Click here to Skip to main content
15,902,750 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello Friends,

I am facing a problem with displaying the openfileDialog in C#.net.
In the Openfiledialog is now displaying all the drives in my system like C:, D:, E:, Network ,MyComputer and all, from which am selecting my required folder path.

But what i need i , I Need to display only the Network Drive folder only in my OpenFileDialog
All other drive folders should not get displayed.

So far i havent found a methos to do it.

Please help me out withsome methods to make this Filtering to be done
Posted

i am agree with Manas .. i dont think there is any way to filter with drives: but u can to following stuff as shown:

OpenFileDialog ofd = new OpenFileDialog();
ofd.CustomPlaces.Clear();
foreach (var item in System.IO.DriveInfo.GetDrives())
{
if (item.DriveType == DriveType.Removable)
ofd.CustomPlaces.Add(item.RootDirectory.ToString());
}

if (ofd.ShowDialog() == DialogResult.OK)
{
FileInfo f = new FileInfo(ofd.FileName);
string s = f.Directory.Root.ToString();
DriveInfo df = new DriveInfo(s);
if (df.DriveType == DriveType.Removable)
{
//DO STUFF WITH FILE
}
}
 
Share this answer
 
I don't think that it is possible to to achieve what you are trying to do with OpenFileDialog.

You can either write your own custom dialog or do validation after you have made the selection.
 
Share this answer
 
Use substring function to get the first two characters of the path,
if the path start with \\, it should be a path start with network drive name.
Else, you can cut off the first 3 characters and add the drive name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900