article

Extending The BrowseForFolder Class

Email
Submitted on: 1/1/2015 4:35:00 AM
By: bleh (from psc cd)  
Level: Beginner
User Rating: By 10 Users
Compatibility: C#
Views: 1627
 
     Simply adding a few more options to the BrowseForFolder class submitted by Chris Anderson.


 
				
Extending The Browse For Folder Dialog Class

This code is simpily extending the Browse For Folder Dialog class that was on posted on PSC by Chris Andersen. After using his code, I was interested in knowing if there was any additional options available aside from just being able to set the title. I consulted the MSDN and this is what I came up with. The above screen shot is showing the Browse For Folder dialog with StartLocation set to "MyDocuments" and Style set to "BrowseForEverything"

.StartLocation


The directory in which the browse dialog will start at. (duh) I haven't found a way to specifiy a certain path, like C:\PSC or something of that nature, but there are a number of members that we can use. They are:
  • Desktop
  • Favorites
  • MyComputer
  • MyDocuments
  • MyPictures
  • NetAndDialUpConnections
  • NetworkNeighborhood
  • Printers
  • Recent
  • SendTo
  • StartMenu
  • Templates

.Style


They style of the browse dialog. We have a few different options to choose from.
  • BrowseForComputer
  • BrowseForEverything
  • BrowseForPrinter
  • RestrictToDomain
  • RestrictToFilesystem
  • RestrictToSubfolders
  • ShowTextBox

The Code


Here's an example of how to use the above methods in the Browse For Folder dialog.

using System;
using System.Windows.Forms;
using System.Windows.Forms.Design;
public class BrowseForFolder : FolderNameEditor 
{ 
	FolderNameEditor.FolderBrowser bDialog;
 	
	public BrowseForFolder()
	{ 
		bDialog = new FolderNameEditor.FolderBrowser(); 
	}
 	
	public string browseDialog(string sTitle)
	{
		bDialog.Description = sTitle;
		bDialog.StartLocation = FolderNameEditor.FolderBrowserFolder.MyComputer;
		bDialog.Style = FolderNameEditor.FolderBrowserStyles.RestrictToDomain;
		bDialog.ShowDialog();
		return bDialog.DirectoryPath;
	}
	~BrowseForFolder()
	{
		bDialog.Dispose(); 
	}
}

Useage:


To use this class, make sure you add a reference to System.Design.DLL. Call the class like so:

BrowseForFolder myDialog = new BrowseForFolder();
MessageBox.Show(myDialog.browseDialog("Dialog Title Goes Here");
It's pretty simple. Thanks again to Chris Anderson for the original code.


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.