Quick Search for:  in language:    
Simply,adding,more,options,class,submitted,Ch
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
.Net Stats

 Code: 140,189. lines
 Jobs: 376. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for .Net.
Click here to see a screenshot of this code!Ray Picking for 3d Objects
By Jay1_z on 11/23

(Screen Shot)

Embed Images into Xml Files
By Chris Richards on 11/23


Encryption and Alternate Data Stream
By Philip Pierce on 11/23


Click here to see a screenshot of this code!AddressBook
By Ekong George Ekong on 11/23

(Screen Shot)

Click here to see a screenshot of this code!Command Line Redirection
By kaze on 11/23

(Screen Shot)

Fader
By Ahmad Hammad on 11/23


Click here to see a screenshot of this code!Get content of a web page (simple)
By Tin Trung Dang on 11/22

(Screen Shot)

Retrieve the long path name for a short path name.
By Özgür Aytekin on 11/22


Easy Randomizer
By Christian Müller on 11/22


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Extending The BrowseForFolder Class

Print
Email
 

Submitted on: 5/15/2002 12:54:38 AM
By: Charles Chadwick  
Level: Beginner
User Rating: By 9 Users
Compatibility:C#

Users have accessed this article 9071 times.
 

(About the author)
 
     Simply adding a few more options to the BrowseForFolder class submitted by Chris Anderson.


 
 
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
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
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
5/15/2002 10:07:35 AM:Chris Andersen
Hey cool. I did something useful for a change. :p
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/16/2002 4:14:21 AM:D. de Haas
Very usefull...:-) 5 from me to you both.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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,
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/24/2003 10:49:56 AM:
Browse for computer did not return my computer name. please help
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/24/2003 10:51:07 AM:
browse for computer does not return the computer name
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
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.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | .Net Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.