How to port BrowseForFolder from VBScript to C#/WPF?
I need some kind of dialog for browsing the local SMB network for file shares. VBScript does it like this.
Set application = CreateObject("Shell.Application")
Set folder = application.BrowseForFolder(0, "Moo!", &h250, &h12) ' &h12 sets
' Network 开发者_JAVA技巧as the root folder.
So I added a reference to Forms and tried to do it with FolderBrowserDialog, but to my surprise:
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. */
Then I looked for a pinvokable function in the Windows API that does this, but didn't find any.
The native Windows function is SHBrowseForFolder
but under .NET you should use the FolderBrowserDialog
class
精彩评论