473,729 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 23135
On Jun 27, 10:31*pm, SpreadTooThin <bjobrie...@gma il.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.GetDirecto ryName to get the path(directory)
and you can use Path.VolumeSepa ratorChar 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...@gma il.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.GetDirecto ryName to get the path(directory)
and you can use Path.VolumeSepa ratorChar to split the filename and use
the first part. There could be better way of doing this.
Path.GetDirecto ryName?
I don't know where Path is what class is that?
..
Jun 28 '08 #3
On Jun 27, 10:46*pm, SpreadTooThin <bjobrie...@gma il.comwrote:
On Jun 27, 8:40*pm, parez <psaw...@gmail. comwrote:
On Jun 27, 10:31*pm, SpreadTooThin <bjobrie...@gma il.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.GetDirecto ryName to get the path(directory)
and you can use Path.VolumeSepa ratorChar to split the filename and use
the first part. There could be better way of doing this.

Path.GetDirecto ryName?
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...@gma il.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.InitialDir ectory = @"c:\";
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterInde x = 2;
fdlg.RestoreDir ectory = true;
if (fdlg.ShowDialo g() == DialogResult.OK )
{
string dirName =
System.IO.Path. GetDirectoryNam e(fdlg.FileName );
string drive =
dirName.Split(S ystem.IO.Path.V olumeSeparatorC har)[0];
MessageBox.Show (dirName);
MessageBox.Show (drive);
}

Hopefully this should help...
Jun 28 '08 #5
On Jun 28, 12:12*pm, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
On Jun 28, 7:31 am, SpreadTooThin <bjobrie...@gma il.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.InitialDir ectory = @"c:\";
* * * * * * fdlg.Filter = "All files (*.*)|*.*|All files (*..*)|*.*";
* * * * * * fdlg.FilterInde x = 2;
* * * * * * fdlg.RestoreDir ectory = true;
* * * * * * if (fdlg.ShowDialo g() == DialogResult.OK )
* * * * * * {
* * * * * * * * string dirName =
System.IO.Path. GetDirectoryNam e(fdlg.FileName );
* * * * * * * * string drive =
dirName.Split(S ystem.IO.Path.V olumeSeparatorC har)[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...@gma il.comwrote:
On Jun 28, 12:12 pm, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
On Jun 28, 7:31 am, SpreadTooThin <bjobrie...@gma il.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.InitialDir ectory = @"c:\";
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterInde x = 2;
fdlg.RestoreDir ectory = true;
if (fdlg.ShowDialo g() == DialogResult.OK )
{
string dirName =
System.IO.Path. GetDirectoryNam e(fdlg.FileName );
string drive =
dirName.Split(S ystem.IO.Path.V olumeSeparatorC har)[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
3260
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: /python/nondist/sandbox/path/{path.py,test_path.py} One thing is still different, though: a Path instance won't compare to a regular string.
2
2561
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 save the ..Text property to an xml file. Nothing happens, the filename is not writen to the xml file, and there is no exception. When I replace the OpenFileDialog with a FolderBrowserDialog and I
3
360
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 (*.mdb)|*.mdb|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) DataBaseLocation.Text = openFileDialog.FileName;
4
8008
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 Explorer i am getting error saying that cannot delete that folder as some process is using it. After that i selected a file from the same folder in OpenFileDialog. When i tried to delete the folder after selecting the file also it is giving the...
2
6720
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 save the ..Text property to an xml file. Nothing happens, the filename is not writen to the xml file, and there is no exception. When I replace the OpenFileDialog with a FolderBrowserDialog and I
2
4936
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
1664
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 (9-27-2005,1210PM.mdb) *Note This Is The Current System Date And Time Of The Save.* I would like to have the function where when the user selects The "Restore Database" button (btnRestore) that it will use an Open File Dialog box and let them...
1
3293
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
1475
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 there a way to group policy (if so, pls. show me), we are using windows xp pro as our client pc and windows server 2003 std edtn R2 as our server. your help is very much appreciated Thanks, James
0
8761
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.