471,851 Members | 894 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,851 software developers and data experts.

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 22954
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
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.