如何将BrowseForFolder从VBScript移植到C#/ WPF?

时间:2009-10-27 10:01:10

标签: c# wpf winforms winapi vbscript

我需要某种对话框来浏览本地SMB网络以获取文件共享。 VBScript就是这样的。

Set application = CreateObject("Shell.Application")
Set folder = application.BrowseForFolder(0, "Moo!", &h250, &h12) ' &h12 sets
' Network as the root folder.

所以我添加了对Forms的引用并试图用FolderBrowserDialog来做,但令我惊讶的是:

FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.RootFolder = /* The Environment.SpecialFolder enumeration doesn't have
a value Network! */
dialog.RootFolder = (Environment.SpecialFolder)0x12; /* This dirty trick doesn't
work too. */

然后我在Windows API中寻找一个可以执行此操作的pinvokable函数,但没有找到任何函数。

1 个答案:

答案 0 :(得分:1)

本机Windows函数是SHBrowseForFolder但在.NET下你应该使用FolderBrowserDialog