473,388 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 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 23105
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Reinhold Birkenfeld | last post by:
Hi, the arguments in the previous thread were convincing enough, so I made the Path class inherit from str/unicode again. It still can be found in CVS:...
2
by: Koala Beer | last post by:
Hi, Here is something I can't figure out what I am doing wrong: I use a OpenFileDialog to select a file. I put the result string from the FileName property in a textbox on my form. Later on I...
3
by: bobrad | last post by:
MAYBE SOMEBODY CAM HELP I AM USING THE FOLLOWING CODE TO GET A LOCATION OF A FILE IN A WINFORM DIALOG OpenFileDialog openFileDialog = new OpenFileDialog(); OpenFileDialog.Filter = " Access...
4
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in...
2
by: Koala Beer | last post by:
Hi, Here is something i can't figure out what i am doing wrong: I use a OpenFileDialog to select a file. I put the result string from the FileName property in a textbox on my form. Later on I...
2
by: Hrcko | last post by:
How can I read just the name of the file? When I put fileName=openFileDialog.FileName I get the full path, but I just want the name of the file. Hrcko
5
by: Webbyz | last post by:
Using vb.net Hello. Here is the problem that I am having. I have a program which makes a copy of my working database (wasa.mdb) and saves it to another folder (/bin/backup/) with the filename...
1
by: psbasha | last post by:
Hi, I would like to get the path of the given file name. Say I/P: C:\Sample\Sample1.txt
2
by: =?Utf-8?B?SmFtZXM=?= | last post by:
Hi, I am aware of 256 characters path limit in naming a file, but can you help me how to limit the path for file naming to 240 characters only? is there a way to limit that in registry editor or is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.