README.md
December 5, 2022 ยท View on GitHub
Description
Simply adding a few more options to the BrowseForFolder class submitted by Chris Anderson.
More Info
| Submitted On | |
| By | bleh |
| Level | Beginner |
| User Rating | 4.7 (47 globes from 10 users) |
| Compatibility | C# |
| Category | GUIs |
| World | .Net (C#, VB.net) |
| Archive File |
Source Code
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.