Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
[STAThread]
static void Main(string[] args)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
// fbd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

if (fbd.ShowDialog() == DialogResult.OK)
{
Console.WriteLine("Hello");

foreach (var path in Directory.GetFiles(fbd.SelectedPath))
{
Console.WriteLine("Please select Folder");
Console.WriteLine(path); // full path
Console.WriteLine(System.IO.Path.GetFileName(path)); // file name
Console.WriteLine("path"+ path);
Console.ReadLine();
}
}


}
}

What I have tried:

I've tried this code for selecting the file but the file is automatically getting selected, as in it allows only to choose the folder and not the file.
Posted
Updated 22-Jul-18 20:29pm
v2

1 solution

Use the OpenFileDialog class if you want to access a file (vs only a folder):

OpenFileDialog Class (System.Windows.Forms)[^]
 
Share this answer
 
Comments
Member 13914334 23-Jul-18 3:28am    
Tried using that but keeps throwing an error:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: The directory name is invalid.

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