Click here to Skip to main content
11,431,483 members (65,698 online)
Click here to Skip to main content

How to Browse Network Folders using Folder Dialog Box Control ?

, 18 Sep 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
An article on how to browse network Folders using VB.NET using Folder Dialog box Control
Screenshot - app_UI.jpg

Screenshot - Browse_Folders.jpg

Introduction

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.

Background

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

    '====== Create folder dialog box object
    Dim objFolderDialog As New FolderBrowserDialog()
    '===== Pass object as Parameter and get Selected network folder
    txtPath.Text = GetNetworkFolders(objFolderDialog)
End Sub

''' <span class="code-SummaryComment"><summary></span>
''' This function will get the Folderdialog as parameter and return the 
''' Selected
''' Folders UNC path. 
''' Ex: <a href="%22%22file://server1/TestFolder'''%22%22">\\Server1\TestFolder
'''</a> <span class="code-SummaryComment"></summary></span>
''' <span class="code-SummaryComment"><param name="oFolderBrowserDialog"></param></span>
''' <span class="code-SummaryComment"><returns>it will return the Selected Folders UNC Path</returns></span>
''' <span class="code-SummaryComment"><remarks></remarks></span>

Public Shared Function GetNetworkFolders(ByVal oFolderBrowserDialog _
      As FolderBrowserDialog) As String
    '======= Get type of Folder Dialog bog
    Dim type As Type = oFolderBrowserDialog.[GetType]
    '======== Get Fieldinfo for rootfolder.
    Dim fieldInfo As Reflection.FieldInfo = type.GetField("rootFolder", _
    BindingFlags.NonPublic Or BindingFlags.Instance)
    '========= Now set the value for Folder Dialog using DirectCast
    '=== 18 = Network Neighborhood is the root
    fieldInfo.SetValue(oFolderBrowserDialog,_
                      DirectCast(18, Environment.SpecialFolder))
    '==== if user click on Ok, then it will return the selected folder.
    '===== otherwise return the blank string.
    If oFolderBrowserDialog.ShowDialog() = DialogResult.OK Then
        Return oFolderBrowserDialog.SelectedPath
    Else
        Return ""
    End If
End Function

fieldInfo.SetValue(oFolderBrowserDialog, DirectCast(18, Environment.SpecialFolder))here you can also set other folder browsers constant.

Here is a list of constants:

Constant Description
0 Desktop folder
1 Internet Explorer
2 Programs folder of the Start menu
3 Control Panel folder
4 Printers folder
5 Documents folder of the Start menu
6 Favorites folder of the Start menu
7 Startup folder of the Start menu
8 Recent folder
9 SendTo folder
10 Recycle Bin folder
11 Start menu folder
16 Desktop (physical) folder
17 My Computer
18 Network Neighborhood
19 Nethood folder
20 Fonts folder
21 Templates folder

Summary

In this way, you can browse Network folders. Let me know if anyone has a problem while using the attached code.

History

  • 18th September, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jatin Prajapati
Team Leader
India India
Jatin is Working in .Net Technology Since 2006. He has Completed Master of Science Degree in Information Technology. He Likes to learn Cutting edge technologies. He has good Skills in Asp.net, Vb.net,C#.Net, Crystal Reports,GDI+, Ajax, WCF, Silverlight SQL Server,IIS Admin,TFA ,Application Architecture Designing.
Follow on   Twitter

Comments and Discussions

 
QuestionVB browse Network folder Pin
Member 1119371430-Oct-14 9:03
memberMember 1119371430-Oct-14 9:03 
QuestionNon shared folder acees is allowed in win xp machine Pin
sagar_25312-Aug-14 22:14
membersagar_25312-Aug-14 22:14 
QuestionThe same path selection problem with phone (portable devices) connected through USB cable [modified] Pin
Member 1100720812-Aug-14 21:34
memberMember 1100720812-Aug-14 21:34 
SuggestionSame idea in C# Pin
Darkangel8616-Oct-12 6:19
memberDarkangel8616-Oct-12 6:19 
GeneralMy vote of 4 Pin
Yas Barrientos8-Oct-11 11:01
memberYas Barrientos8-Oct-11 11:01 
QuestionAny way to enumerate network shares? Pin
dirigo27-Jul-09 11:54
memberdirigo27-Jul-09 11:54 
GeneralWorks! (C# Version) Pin
jp2code20-Jul-09 9:01
memberjp2code20-Jul-09 9:01 
GeneralRe: Works! (C# Version) Pin
tpemc9-Oct-09 9:21
membertpemc9-Oct-09 9:21 
GeneralRe: Works! (C# Version) Pin
jp2code9-Oct-09 10:22
memberjp2code9-Oct-09 10:22 
GeneralRe: Works! (C# Version) Pin
tpemc9-Oct-09 14:08
membertpemc9-Oct-09 14:08 
GeneralRe: Works! (C# Version) Pin
jp2code10-Oct-09 8:53
memberjp2code10-Oct-09 8:53 
GeneralC# version Pin
allothernamesaretaken25-Mar-09 21:48
memberallothernamesaretaken25-Mar-09 21:48 
GeneralRe: C# version Pin
MarMirK14-Jul-09 10:31
memberMarMirK14-Jul-09 10:31 
QuestionHow to Browse Network Folders using Folder Dialog Box Control ? Pin
Anna Tanhueco21-Aug-08 22:46
memberAnna Tanhueco21-Aug-08 22:46 
AnswerRe: How to Browse Network Folders using Folder Dialog Box Control ? Pin
chrisgIT4-Dec-11 8:45
memberchrisgIT4-Dec-11 8:45 
GeneralDisplay Share folders only for local Machine Pin
harpal shergill24-Apr-08 4:46
memberharpal shergill24-Apr-08 4:46 
GeneralRe: Display Share folders only for local Machine Pin
jmcc2k19-Nov-08 23:21
memberjmcc2k19-Nov-08 23:21 
Questionis there possible to get the Shared folder path? Pin
my4color20-Mar-08 21:00
membermy4color20-Mar-08 21:00 
AnswerRe: is there possible to get the Shared folder path? Pin
Jatin Prajapati22-Mar-08 6:11
memberJatin Prajapati22-Mar-08 6:11 
GeneralRe: is there possible to get the Shared folder path? Pin
my4color23-Mar-08 20:14
membermy4color23-Mar-08 20:14 
QuestionBrowsing the Folder Dialog Box in Web Application Pin
dardnaho3-Feb-08 18:37
memberdardnaho3-Feb-08 18:37 
GeneralRe: Browsing the Folder Dialog Box in Web Application Pin
Jatin Prajapati17-Feb-08 23:53
memberJatin Prajapati17-Feb-08 23:53 
GeneralRe: Browsing the Folder Dialog Box in Web Application Pin
dardnaho18-Feb-08 21:55
memberdardnaho18-Feb-08 21:55 
GeneralRe: Browsing the Folder Dialog Box in Web Application Pin
Jatin Prajapati20-Feb-08 20:09
memberJatin Prajapati20-Feb-08 20:09 
GeneralRe: Browsing the Folder Dialog Box in Web Application Pin
dardnaho3-Mar-08 2:07
memberdardnaho3-Mar-08 2:07 
QuestionDirectCast is frustrating me Pin
Warrington_Minge25-Nov-07 14:02
memberWarrington_Minge25-Nov-07 14:02 
QuestionJust Select the Computer Pin
Mr. Jiggs11-Oct-07 10:09
memberMr. Jiggs11-Oct-07 10:09 
AnswerRe: Just Select the Computer Pin
Jatin Prajapati11-Oct-07 22:51
memberJatin Prajapati11-Oct-07 22:51 
QuestionRe: Just Select the Computer Pin
Mr. Jiggs12-Oct-07 0:50
memberMr. Jiggs12-Oct-07 0:50 
AnswerRe: Just Select the Computer Pin
Jatin Prajapati12-Oct-07 3:53
memberJatin Prajapati12-Oct-07 3:53 
AnswerRe: Just Select the Computer Pin
Mr. Jiggs12-Oct-07 4:16
memberMr. Jiggs12-Oct-07 4:16 
GeneralRe: Just Select the Computer Pin
Mr. Jiggs18-Oct-07 11:14
memberMr. Jiggs18-Oct-07 11:14 
QuestionAre the numbers documented? Pin
Hei-Tech1-Oct-07 5:53
memberHei-Tech1-Oct-07 5:53 
AnswerRe: Are the numbers documented? Pin
Jatin Prajapati1-Oct-07 6:09
memberJatin Prajapati1-Oct-07 6:09 
AnswerRe: Are the numbers documented? Pin
Hei-Tech1-Oct-07 6:18
memberHei-Tech1-Oct-07 6:18 
QuestionCombining 2 Spetial Folders ?? Pin
itais1701E27-Sep-07 13:29
memberitais1701E27-Sep-07 13:29 
AnswerRe: Combining 2 Spetial Folders ?? [modified] Pin
Jatin Prajapati27-Sep-07 21:22
memberJatin Prajapati27-Sep-07 21:22 
GeneralRe: Combining 2 Spetial Folders ?? Pin
itais1701E28-Sep-07 4:37
memberitais1701E28-Sep-07 4:37 
GeneralRe: Combining 2 Spetial Folders ?? Pin
Jatin Prajapati28-Sep-07 6:16
memberJatin Prajapati28-Sep-07 6:16 
QuestionHow can this be achieved in a browser? Pin
RobNagel27-Sep-07 4:11
memberRobNagel27-Sep-07 4:11 
AnswerRe: How can this be achieved in a browser? Pin
Jatin Prajapati27-Sep-07 4:22
memberJatin Prajapati27-Sep-07 4:22 
GeneralRe: How can this be achieved in a browser? Pin
RobNagel27-Sep-07 4:35
memberRobNagel27-Sep-07 4:35 
GeneralRe: How can this be achieved in a browser? Pin
Jatin Prajapati27-Sep-07 8:06
memberJatin Prajapati27-Sep-07 8:06 
GeneralRe: How can this be achieved in a browser? Pin
RobNagel28-Sep-07 0:25
memberRobNagel28-Sep-07 0:25 
GeneralRe: How can this be achieved in a browser? Pin
Jatin Prajapati28-Sep-07 2:10
memberJatin Prajapati28-Sep-07 2:10 
GeneralNetwork folder Pin
Perora18-Sep-07 8:07
memberPerora18-Sep-07 8:07 
GeneralRe: Network folder Pin
Jatin Prajapati18-Sep-07 8:09
memberJatin Prajapati18-Sep-07 8:09 
GeneralRe: Network folder Pin
Perora18-Sep-07 8:36
memberPerora18-Sep-07 8:36 
GeneralRe: Network folder Pin
Jatin Prajapati18-Sep-07 8:43
memberJatin Prajapati18-Sep-07 8:43 
GeneralRe: Network folder Pin
Perora19-Sep-07 0:59
memberPerora19-Sep-07 0:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150428.2 | Last Updated 18 Sep 2007
Article Copyright 2007 by Jatin Prajapati
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid