|
|
|
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"
.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 |
|
|
Your Vote! |
See Voting Log |
|
Other User Comments |
5/15/2002 10:07:35 AM:Chris Andersen Hey cool. I did something useful for a
change. :p
|
5/16/2002 4:14:21 AM:D. de Haas Very usefull...:-)
5 from me to you
both.
|
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].
Other than
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
FolderNameEditor.privateOptions to
"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
empty.
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 Nice coding.
Vote of Excellent from
me.
Hi,
Do you want to make money
with your programming skills
?
Software Objects provide following
services :
1)Sell your
software.
2)Post a software to be
done.
3)Bid on the software
projects.
4)Buy software
Thanks and
have a nice day.
Software
Objects
http://www.thesoftwareobjects.c
om
|
3/12/2003 7:25:03 AM: Hi,
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
cancel.
Use dlgResult =
bDialog.Showdialog()
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
wrong, please)
Greetings,
|
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
computer name
|
|
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. |
|