469,360 Members | 1,807 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

Get OpenFileDialog filename path...

After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive and path where that file is.
What function, method, class can I use in C# to get the drive and
path?
Jun 28 '08 #1
6 22599
On Jun 27, 10:31*pm, SpreadTooThin <bjobrie...@gmail.comwrote:
After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive and path where that file is.
What function, method, class can I use in C# to get the drive and
path?

You can use the Path.GetDirectoryName to get the path(directory)
and you can use Path.VolumeSeparatorChar to split the filename and use
the first part. There could be better way of doing this.
Jun 28 '08 #2
On Jun 27, 8:40*pm, parez <psaw...@gmail.comwrote:
On Jun 27, 10:31*pm, SpreadTooThin <bjobrie...@gmail.comwrote:
After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive and path where that file is.
What function, method, class can I use in C# to get the drive and
path?

You can use the Path.GetDirectoryName to get the path(directory)
and you can use Path.VolumeSeparatorChar to split the filename and use
the first part. There could be better way of doing this.
Path.GetDirectoryName?
I don't know where Path is what class is that?
..
Jun 28 '08 #3
On Jun 27, 10:46*pm, SpreadTooThin <bjobrie...@gmail.comwrote:
On Jun 27, 8:40*pm, parez <psaw...@gmail.comwrote:
On Jun 27, 10:31*pm, SpreadTooThin <bjobrie...@gmail.comwrote:
After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive and path where that file is.
What function, method, class can I use in C# to get the drive and
path?
You can use the Path.GetDirectoryName to get the path(directory)
and you can use Path.VolumeSeparatorChar to split the filename and use
the first part. There could be better way of doing this.

Path.GetDirectoryName?
I don't know where Path is what class is that?
..
System.IO
Jun 28 '08 #4
On Jun 28, 7:31 am, SpreadTooThin <bjobrie...@gmail.comwrote:
After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive andpathwhere that file is.
What function, method, class can I use in C# to get the drive andpath?
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "C# Help";
fdlg.InitialDirectory = @"c:\";
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
string dirName =
System.IO.Path.GetDirectoryName(fdlg.FileName);
string drive =
dirName.Split(System.IO.Path.VolumeSeparatorChar)[0];
MessageBox.Show(dirName);
MessageBox.Show(drive);
}

Hopefully this should help...
Jun 28 '08 #5
On Jun 28, 12:12*pm, Duggi <DuggiSrinivasa...@gmail.comwrote:
On Jun 28, 7:31 am, SpreadTooThin <bjobrie...@gmail.comwrote:
After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive andpathwhere that file is.
What function, method, class can I use in C# to get the drive andpath?

* * * * * * OpenFileDialog fdlg = new OpenFileDialog();
* * * * * * fdlg.Title = "C# Help";
* * * * * * fdlg.InitialDirectory = @"c:\";
* * * * * * fdlg.Filter = "All files (*.*)|*.*|All files (*..*)|*.*";
* * * * * * fdlg.FilterIndex = 2;
* * * * * * fdlg.RestoreDirectory = true;
* * * * * * if (fdlg.ShowDialog() == DialogResult.OK)
* * * * * * {
* * * * * * * * string dirName =
System.IO.Path.GetDirectoryName(fdlg.FileName);
* * * * * * * * string drive =
dirName.Split(System.IO.Path.VolumeSeparatorChar)[0];
* * * * * * * * MessageBox.Show(dirName);
* * * * * * * * MessageBox.Show(drive);
* * * * * * }

Hopefully this should help...
Thats great thanks!
Remindes me of borland fnsplit, which gave you drive, path filename
and extension.
Jun 28 '08 #6
On Jun 29, 4:52 am, SpreadTooThin <bjobrie...@gmail.comwrote:
On Jun 28, 12:12 pm, Duggi <DuggiSrinivasa...@gmail.comwrote:
On Jun 28, 7:31 am, SpreadTooThin <bjobrie...@gmail.comwrote:
After I select a file with the OpenFileDialog, I get the file name
with .FileName,
but I want to know the drive andpathwhere that file is.
What function, method, class can I use in C# to get the drive andpath?
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "C# Help";
fdlg.InitialDirectory = @"c:\";
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterIndex = 2;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
string dirName =
System.IO.Path.GetDirectoryName(fdlg.FileName);
string drive =
dirName.Split(System.IO.Path.VolumeSeparatorChar)[0];
MessageBox.Show(dirName);
MessageBox.Show(drive);
}
Hopefully this should help...

Thats great thanks!
Remindes me of borland fnsplit, which gave you drive, path filename
and extension.
I hope you got how to do it...

-Cnu
Jul 4 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

34 posts views Thread by Reinhold Birkenfeld | last post: by
2 posts views Thread by Koala Beer | last post: by
3 posts views Thread by bobrad | last post: by
4 posts views Thread by Nagachandra Sekhar Grandhi | last post: by
2 posts views Thread by Hrcko | last post: by
2 posts views Thread by =?Utf-8?B?SmFtZXM=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.