.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Working with FolderBrowserDialog in VB.NET

Posted By:Abhisek Panda       Posted Date: November 10, 2009    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

        First create a window application in VB.Net and add a FolderBrowserDialog controll to it. Also add a textbox(txtFolder) and button( btnBrowseFolders).

        The button's work here is to open the FolderBrowserDialog and user can select any folder or file to be displayed in the text box. Now double click on the button and add the following code in it.

Private Sub btnBrowseFolders_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseFolders.Click
With fldlgList
'set the RootFolder
.RootFolder = Environment.SpecialFolder.Personal
' optional Description to provide additional instructions.
Description = "Select the directory you want to use as the default."
ShowNewFolderButton = True
'Showing the selected folder in the textbox
If ShowDialog = Windows.Forms.DialogResult.OK Then
txtFolder.Text = .SelectedPath
End If

End With

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)

End Try

End Sub


After creating a new FolderBrowserDialog, you have to set the RootFolder to the location from which to start browsing. You can choose from the list of system special folders, such as Program Files, Programs, System, or Startup, which contain common information.

RootFolder = Environment.SpecialFolder.Personal
We can give user optional information about the bowser using the Description property.
Description = "Select the directory you want to use as the default."
You can use the ShowNewFolderButton property to control if the user is able to create new folders via the New Folder button in the browse dialogue window.
ShowNewFolderButton = True


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend