By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,449 Members | 1,414 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,449 IT Pros & Developers. It's quick & easy.

OpenFileDialog !

P: n/a
Hello,

using openfiledialog, how can I retrieve the path ?

thx
Nov 15 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
L#
On Wed, 4 Feb 2004 19:53:38 -0800, "C# newbie"
<rs****@otxresearch.com> wrote:
Hello,

using openfiledialog, how can I retrieve the path ?

thx


OpenFileDialog o = new OpenFileDialog();
if (o.ShowDialog() == DialogResult.OK)
{
string fn = Path.GetFileName(o.FileName);
string path = Path.GetDirectoryName(o.FileName);
}
--
Ludwig
mailto:ludwig_(nospamplease)stuyck@pandora(nospamp lease).be
Nov 15 '05 #2

P: n/a
Hi there,

First add a reference to System.Design.dll and then the following code
should work:

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.RestrictToDom ain;
bDialog.ShowDialog();
return bDialog.DirectoryPath;
}
~BrowseForFolder()
{
bDialog.Dispose();
}
}

This code is from here:
http://www.planet-source-code.com/vb...odeId=275&lngW
Id=10

The article says you can call the code like so:

BrowseForFolder myDialog = new BrowseForFolder();
MessageBox.Show(myDialog.browseDialog("Dialog Title Goes Here");

But if you want to be able to determine what the user pressed, you can do
something like the following:

DialogResult result = myDialog.ShowDialog()

You can find more about the DialogResult at:
http://msdn.microsoft.com/library/de...s/cpref/html/f
rlrfsystemwindowsformsdialogresultclasstopic.asp

Good luck!

Mack D. Male
MVP Visual Developer - Academic
"C# newbie" <rs****@otxresearch.com> wrote in message
news:#g**************@TK2MSFTNGP12.phx.gbl...
Hello,

using openfiledialog, how can I retrieve the path ?

thx

Nov 15 '05 #3

P: n/a
Thanks. The thing is I'm useing the path either but compiler complains on
path!
Any suggestions ?

Regards


"L#" <ludwig_(nospamplease)stuyck@pandora(nospamplease) .be> wrote in message
news:1o********************************@4ax.com...
On Wed, 4 Feb 2004 19:53:38 -0800, "C# newbie"
<rs****@otxresearch.com> wrote:
Hello,

using openfiledialog, how can I retrieve the path ?

thx


OpenFileDialog o = new OpenFileDialog();
if (o.ShowDialog() == DialogResult.OK)
{
string fn = Path.GetFileName(o.FileName);
string path = Path.GetDirectoryName(o.FileName);
}
--
Ludwig
mailto:ludwig_(nospamplease)stuyck@pandora(nospamp lease).be

Nov 15 '05 #4

P: n/a
L#
On Thu, 5 Feb 2004 12:39:56 -0800, "C# newbie"
<rs****@otxresearch.com> wrote:
Thanks. The thing is I'm useing the path either but compiler complains on
path!
Any suggestions ?

Regards


I'm sorry, I'm afraid I don't understand your question?

--
Ludwig
mailto:ludwig_(nospamplease)stuyck@pandora(nospamp lease).be
Nov 15 '05 #5

P: n/a
Hi Ludwig,

Thanks for your quick response. Regarding your code :

OpenFileDialog o = new OpenFileDialog();
if (o.ShowDialog() == DialogResult.OK)
{
string fn = Path.GetFileName(o.FileName);
string path = Path.GetDirectoryName(o.FileName);
}

the compiler complains about "Path". Also, after adding a dot to "Path"
Intellisence does't come upand doesn't show any method related. I was
assuming that Path is a member of the OpenFileDialog class.

Any idea?

Thanks in advance

"L#" <ludwig_(nospamplease)stuyck@pandora(nospamplease) .be> wrote in message
news:vv********************************@4ax.com...
On Thu, 5 Feb 2004 12:39:56 -0800, "C# newbie"
<rs****@otxresearch.com> wrote:
Thanks. The thing is I'm useing the path either but compiler complains on
path!
Any suggestions ?

Regards


I'm sorry, I'm afraid I don't understand your question?

--
Ludwig
mailto:ludwig_(nospamplease)stuyck@pandora(nospamp lease).be

Nov 15 '05 #6

P: n/a
L#
On Thu, 5 Feb 2004 13:49:57 -0800, "C# newbie"
<rs****@otxresearch.com> wrote:
Hi Ludwig,

Thanks for your quick response. Regarding your code :

OpenFileDialog o = new OpenFileDialog();
if (o.ShowDialog() == DialogResult.OK)
{
string fn = Path.GetFileName(o.FileName);
string path = Path.GetDirectoryName(o.FileName);
}

the compiler complains about "Path". Also, after adding a dot to "Path"
Intellisence does't come upand doesn't show any method related. I was
assuming that Path is a member of the OpenFileDialog class.

Any idea?


No, Path is a System.IO class, so use System.IO.Path, or put "using
System.IO;" on top.
--
Ludwig
mailto:ludwig_(nospamplease)stuyck@pandora(nospamp lease).be
Nov 15 '05 #7

P: n/a
Yes, you're right. works.

thanks a lot
"L#" <ludwig_(nospamplease)stuyck@pandora(nospamplease) .be> wrote in message
news:u1********************************@4ax.com...
On Thu, 5 Feb 2004 13:49:57 -0800, "C# newbie"
<rs****@otxresearch.com> wrote:
Hi Ludwig,

Thanks for your quick response. Regarding your code :

OpenFileDialog o = new OpenFileDialog();
if (o.ShowDialog() == DialogResult.OK)
{
string fn = Path.GetFileName(o.FileName);
string path = Path.GetDirectoryName(o.FileName);
}

the compiler complains about "Path". Also, after adding a dot to "Path"
Intellisence does't come upand doesn't show any method related. I was
assuming that Path is a member of the OpenFileDialog class.

Any idea?


No, Path is a System.IO class, so use System.IO.Path, or put "using
System.IO;" on top.
--
Ludwig
mailto:ludwig_(nospamplease)stuyck@pandora(nospamp lease).be

Nov 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.