Results 1 to 7 of 7

Thread: Browse for Folder **RESOLVED**

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    30

    Question Browse for Folder **RESOLVED**

    Ok, i know this must've been posted a million times in VB but I'm a new C# programmer and frankly I have no clue as how to do this in C#, so please help me out

    Code:
    private void button3_Click(object sender, System.EventArgs e)
    {
    	OpenFileDialog openFileDialog1 = new OpenFileDialog();
    	openFileDialog1.ShowDialog();
    	textBox1.Text = openFileDialog1.FileName;
    }
    How do I turn this into a Folder browsing dialog? This only selects existing files. I've seen the VB code involved for this and it's, for a lack of a better word, ridiculously complex! Isn't there a built-in method or class for this in C#? Thanks in advance!
    Last edited by eanatum; May 7th, 2003 at 01:06 PM.

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    There is a folder browser dialog in VS.NET 2003. There is none in VS.NET 2002, so you will have to use API calls are you can use a custom control from this website http://www.sellsbrothers.com

  3. #3
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    that aint truth, you can use the System.Design.FolderNameEditor if i am not mistaken
    \m/\m/

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Originally posted by PT Exorcist
    that aint truth, you can use the System.Design.FolderNameEditor if i am not mistaken
    He may be able to use that, but I dont think thats what he is looking for.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    30

    Smile

    Actually, I think it is! The link provided by Cander had exactly what I needed. This is what I ended up with:

    Code:
    using System.Windows.Forms.Design; // Necessary for BrowseForFolder
    
    public class BrowseForFolder : FolderNameEditor 
    { 
    	FolderNameEditor.FolderBrowser fBrowser;
    
    	public BrowseForFolder()
    	{
    		fBrowser = new System.Windows.Forms.Design.FolderNameEditor.FolderBrowser();
    	}
    
    	public string ShowIt(string textDescription)
    	{
    		fBrowser.Description = textDescription;
    		fBrowser.ShowDialog();
    		return fBrowser.DirectoryPath;
    	}
    
    	~BrowseForFolder()
    	{
    		fBrowser.Dispose();
    	}
    }
    
    private void button3_Click(object sender, System.EventArgs e)
    {
    BrowseForFolder folderDialog = new BrowseForFolder();
    textBox1.Text = folderDialog.ShowIt("Please select a folder:");
    }
    IMPORTANT: You must also add a reference to 'System.Design.dll' in the Solution Explorer for this to work.

    I got this working perfectly. Hope this code helps others. Thanks a million, guys!

  7. #7
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    IMPORTANT: You must also add a reference to 'System.Design.dll' in the Solution Explorer for this to work.
    I keep forgetting to tell people that!
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width