Click here to Skip to main content
15,908,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi By command “OpenFileDialog()” I can access to a file in every path. But I want to access to directory no to file. I wants to get only name of directory as parameter. But OpenFileDialog()
Get name of file and it’s path.
Is there any command in c# for it?

How can I do this?
Thanks very much
Posted

You can use the FolderBrowserDialog[^] class instead of the FileDialog one.
 
Share this answer
 
If you need to use OpenFileDialog for some reason, and the FolderBrowserDialog suggested by Abhinav S is not enough, you still can get folder name by using Path.GetDirectoryName[^] on the selected file name.
If you need to be able to select folder and/or file in the same dialog, this can be a solution: https://github.com/scottwis/OpenFileOrFolderDialog[^], but there are other solutions too for this task out there...
 
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