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

Get OpenFileDialog filename path...

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.