Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
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"
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:
They style of the browse dialog. We have a few different options to choose from.
Here's an example of how to use the above methods in the Browse For Folder dialog.
public class BrowseForFolder : FolderNameEditor
bDialog = new FolderNameEditor.FolderBrowser();
public string browseDialog(string sTitle)
bDialog.Description = sTitle;
bDialog.StartLocation = FolderNameEditor.FolderBrowserFolder.MyComputer;
bDialog.Style = FolderNameEditor.FolderBrowserStyles.RestrictToDomain;
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|
See Voting Log |
|Other User Comments|
|5/15/2002 10:07:35 AM:Chris Andersen|
Hey cool. I did something useful for a
|5/16/2002 4:14:21 AM:D. de Haas|
5 from me to you
|7/26/2002 3:17:03 AM:Eirik|
Very usefull code, but it has one minor
problem. It has no ability if the user
pressed [OK] or [Cancel].
that it's very clean and usefull.
|11/8/2002 10:01:18 PM:|
When I tried this it did not show the
tree that shows the folders. It did
show the buttons and the text box
though. Any suggestions?
|11/18/2002 9:07:56 PM:|
I found that the code works great, it
did exactly what I needed it to. It
then wouldn't display the folders box
anymore. I played around with it and
found that icons on the form were
causing the problem. Either using an
imagelist or image property of a
control. Haven't figured out how to
get around that though.
|12/10/2002 6:09:50 PM:|
I was trying to use your code example
for browsing for computers. It seems I
had to modify the
"BrowseForComputer" before it would
give me the correct dialog. As well, I
could not get it to return me the name
of the computer just selected.
"DirectoryPath" is always
Also MSDN says not to invoke
FolderNameEditor class directly in your
code. Don't quite understand that
warning since you obviously used it.
|2/24/2003 3:14:17 PM:nfs|
Vote of Excellent from
Do you want to make money
with your programming skills
Software Objects provide following
2)Post a software to be
3)Bid on the software
have a nice day.
|3/12/2003 7:25:03 AM:|
You didn't have to look at MSDN
for this, the intellisense shows all
properties that you can use. Anyway,
just a remark, the showdialog method
returns a dialogresult value so you can
determine if the user pressed OK or
Use dlgResult =
I also found that
you can only create a new class and
inherit from the FolderNameEditor
class. You can't use this directly from
within a form. (correct me if i'm
|3/24/2003 10:49:56 AM:|
Browse for computer did not return my
computer name. please help
|3/24/2003 10:51:07 AM:|
browse for computer does not return the
| Add Your Feedback! |
|Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name. |
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here.