In the Folder Browse dialog box, we can browse our required folder except Network Neighborhood as a root folder. To browse the Network folders using Folder Dialog box control is quite difficult. I have seen lots of solutions on the Internet and found several lines of code to achieve this thing. But here, I am showing you a few lines code to achieve the same thing.
I was developing one distributed application and my requirement was to browse only the
Network folders. I searched the Internet for this problem and found that the folder dialog
box control does not directly support Network folders browsing like Desktop folder or
other folders. This article will help you to do this thing in an easy manner.
Using the Code
The code that I have written to browse Network folders is quite easy to understand. Here is the code.
Private Sub btnBrowse_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnBrowse.Click
Dim objFolderDialog As New FolderBrowserDialog()
txtPath.Text = GetNetworkFolders(objFolderDialog)
Public Shared Function GetNetworkFolders(ByVal oFolderBrowserDialog _
As FolderBrowserDialog) As String
Dim type As Type = oFolderBrowserDialog.[GetType]
Dim fieldInfo As Reflection.FieldInfo = type.GetField("rootFolder", _
BindingFlags.NonPublic Or BindingFlags.Instance)
If oFolderBrowserDialog.ShowDialog() = DialogResult.OK Then
fieldInfo.SetValue(oFolderBrowserDialog, DirectCast(18, Environment.SpecialFolder))here you can also set other folder browsers constant.
Here is a list of constants:
||Programs folder of the Start menu
||Control Panel folder
||Documents folder of the Start menu
||Favorites folder of the Start menu
||Startup folder of the Start menu
||Recycle Bin folder
||Start menu folder
||Desktop (physical) folder
In this way, you can browse Network folders. Let me know if anyone has a problem while using the attached code.
- 18th September, 2007: Initial post