访问所选目录(通过C#) [英] Access to selected directory (by C#)

查看:81
本文介绍了访问所选目录(通过C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
通过命令OpenFileDialog()我可以访问每个路径中的文件。但我想访问目录no to file。我想只获取目录名称作为参数。但是OpenFileDialog()

获取文件的名称及其路径。

c#中是否有任何命令用于它?



我该怎么做?

非常感谢

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

推荐答案

你可以使用 FolderBrowserDialog [ ^ ]类而不是FileDialog。
You can use the FolderBrowserDialog[^] class instead of the FileDialog one.


如果出于某种原因需要使用 OpenFileDialog ,并且建议使用 FolderBrowserDialog Abhinav S还不行,您仍然可以使用 Path.GetDirectoryName <获取文件夹名称/ a> [ ^ ]。

如果你需要在同一个对话框中选择文件夹和/或文件,这可以是一个解决方案: https://github.com/scottwis/OpenFileOrFolderDialog [ ^ ],但是还有其他解决方案可用于此任务......
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...


这篇关于访问所选目录(通过C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆