473,698 Members | 2,480 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 23131
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
3255
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
2559
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
8001
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
6716
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
4935
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
1663
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
3292
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
1472
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
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
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
9161
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
9029
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
7732
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...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2006
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.