Below code is opening Folder Browser dialog on button click, I want that if mine PC is in network..In Folder Browser Dialog even the network drives are coming,I want that Network Places do not come in treeview.Is it possible??

Option Strict On
Option Explicit On
Option Compare Text

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim obj As New FolderBrowserDialog
            If obj.ShowDialog = Windows.Forms.DialogResult.OK Then
                MsgBox(obj.SelectedPath)
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

Dani AI

Generated

Short answer: the built‑in FolderBrowserDialog cannot hide the top‑level "Network" or "Network Places" node. As noted by , the only reliable choices are to use a custom picker or a third‑party control; setting RootFolder (as mentioned) only changes where browsing starts, it doesn't remove virtual shell nodes. 's suggestion to use a third‑party folder control is reasonable if a polished, drop‑in UI is preferred.

A practical, common approach is a tiny custom dialog that builds its own TreeView and populates only desired roots (for example, local fixed drives). The sample below shows the pattern: enumerate drives with DriveInfo, skip DriveType.Network, add a dummy child for lazy expansion, and on expand enumerate subfolders with exception handling so inaccessible folders are skipped.

' Simple VB.NET folder picker that omits network drives
Public Function PickFolder() As String
    Using dlg As New Form()
        Dim tv As New TreeView With {.Dock = DockStyle.Fill}
        Dim ok As New Button With {.Text = "OK", .Dock = DockStyle.Bottom}
        Dim cancel As New Button With {.Text = "Cancel", .Dock = DockStyle.Bottom}
        dlg.Controls.Add(tv) : dlg.Controls.Add(ok) : dlg.Controls.Add(cancel)

        For Each d As IO.DriveInfo In IO.DriveInfo.GetDrives()
            If d.DriveType <> IO.DriveType.Network AndAlso d.IsReady Then
                Dim n As New TreeNode(d.Name) With {.Tag = d.RootDirectory.FullName}
                n.Nodes.Add("placeholder") : tv.Nodes.Add(n)
            End If
        Next

        AddHandler tv.BeforeExpand, Sub(s, e)
            If e.Node.Nodes.Count = 1 AndAlso e.Node.Nodes(0).Text = "placeholder" Then
                e.Node.Nodes.Clear()
                Try
                    For Each subdir As String In IO.Directory.GetDirectories(CStr(e.Node.Tag))
                        Dim ni As New TreeNode(IO.Path.GetFileName(subdir)) With {.Tag = subdir}
                        Try
                            If IO.Directory.GetDirectories(subdir).Length > 0 Then ni.Nodes.Add("placeholder")
                        Catch : End Try
                        e.Node.Nodes.Add(ni)
                    Next
                Catch : End Try
            End If
        End Sub

        Dim result As String = Nothing
        AddHandler ok.Click, Sub()
            If tv.SelectedNode IsNot Nothing Then result = CStr(tv.SelectedNode.Tag) : dlg.DialogResult = DialogResult.OK : dlg.Close()
        End Sub
        AddHandler cancel.Click, Sub() dlg.Close()

        If dlg.ShowDialog() = DialogResult.OK Then Return result
        Return Nothing
    End Using
End Function

Notes and cautions: mapped network drives appear in DriveInfo as DriveType.Network and are filtered by the sample; UNC entries that are not mapped won't appear unless explicitly added. Lazy population and broad exception handling (UnauthorizedAccessException, IO errors) are essential for responsiveness. For a production UI, add icons, nicer error handling, and an option to include network drives on demand or use a vetted third‑party picker if richer shell behavior is needed.

Recommended Answers

All 3 Replies

you can create your own broserdialog to avoid that. but its not possible wth the orginal one.

From the Microsoft help for FolderBrowserDialog class:

Typically, after creating a new FolderBrowserDialog, you set the RootFolder to the location from which to start browsing. Optionally, you can set the SelectedPath to an absolute path of a subfolder of RootFolder that will initially be selected.

Are you possibly setting the SelectedPath to a location that doesn't equate to a subfolder of RootFolder (i.e. My Computer)? That would probably cause it to dive back to the RootFolder as the presented location.

folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyDocuments;

The Folder browser dialog cannot do filtering. FolderView () will do what you want along with many other things.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.