Click to See Complete Forum and Search --> : BrowseForFolder (c#)
no1bitwdlr
January 3rd, 2002, 01:13 PM
Does anyone know how to get the "Browse For Folder" dialog to show up using C#, and give me back the path upon dismissal. I tried adding a reference to Shell32.dll and using the "ShellClass" class to call "BrowseForDialog(...)". This works to display the dialog, but it returns a Shell32.Folder object, and I have no idea how to get the path from that. If anyone has any ideas, I would sure appreciate some help. thanks
no1bitwdlr
January 3rd, 2002, 03:43 PM
I figured it out. Here it is if you are curious...
First add a reference to Shell32.dll. Next, wherever you want the browse dialog box to show, do this...
some_func()
{
Shell32.ShellClass shell_class = new Shell32.ShellClass();
//Note that param 3 and param 4 control the appearance
//of the dialog box. These defaults are a good start
Shell32.Folder3 folder_3 = (Shell32.Folder3) shell_class.BrowseForFolder(this.Handle.ToInt32(), "Browse for whatever reason", 0, 0);
//This is just to prove it worked.
MessageBox.Show(folder_3.Self.Path);
}
If there is a better way, I don't know it.
prie
January 7th, 2002, 12:42 AM
There is a better way. Use following code
using System;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace TestProject
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class OpenFolderDialog : FolderNameEditor
{
FolderBrowser fb;
public OpenFolderDialog()
{
fb = new FolderBrowser();
}
public string GetFolder()
{
DialogResult dr = fb.ShowDialog();
return fb.DirectoryPath;
}
}
}
calling code
OpenFolderDialog open = new OpenFolderDialog();
this.textBox1.Text = open.GetFolder();
Hope this 'll solve your problems
gesutton
January 21st, 2003, 08:24 PM
Here is an answer from Microsoft. I just tried it and it works:
http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b306285
rusky
January 22nd, 2003, 01:34 PM
Ok guys, I have seen so many slutions but still why doesn't anybody point out the fact that there is something called "OpenFileDialog" in the toolbar.. you just add that and then
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
data_string = openFileDialog1.FileName;
}
Or if you want more files just check the multi select option for the openFileDialog and go :
int i;
openFileDialog1.ShowDialog();
for(i=0;i<openFileDialog1.FileNames.Length;i++)
if(doesNotExist(openFileDialog1.FileNames[i])==1)
fileList.Items.Add(openFileDialog1.FileNames[i]);
..if u use a list view control... or just adapt this to whatever suits your needs...
Please take note that I'm somewhat of a begginer at programming and I might be quite off here.. sorry if I missunderstood the topic...
:cool:
pareshgh
February 17th, 2003, 05:53 PM
did you got the working around ?
how did you solve it > plz let us know atleast. I was interested in ur problem.. solution
thanx
Paresh
Cyanide
April 27th, 2007, 08:05 AM
Seems like no one ever posted the easy way of doing it:FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
string myPath = fbd.SelectedPath;
}
Maybe this has been added in more recent versions of .NET and was not available at the original date of this thread, but I still thought I should do this addendum just in case anyone else comes up with the same question and does a forum search. :thumb:
cjard
April 27th, 2007, 08:52 AM
Heh, but 4 years ago.. OP could have died or given up coding by now.. :D
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.