473,395 Members | 1,404 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,395 software developers and data experts.

How do you get path and filename from a SaveFileDialog ?

I want to get the file name and path from a SaveFileDialog (for a
'save as' operation) after the user has saved the information under a
new file name (and presumably under a new path) ?

I want to display the new file name and path in the Form.text Title.
So how do I go about getting the info ?

Heres my code:
private void menu_profile_saveas_Click(object sender,
System.EventArgs e)
{
//Open file for reading
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = geoData.GetFilePath();
saveFileDialog1.Filter = "DAT31-8 Files
(*.N31)|*.n31|All Files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true ;
//read and filter the raw data
if(saveFileDialog1.ShowDialog() ==
DialogResult.OK)
{
geoData.SaveToN31File(saveFileDialog1.FileName);

}

}

Could someone please help ?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #1
2 50216
I'm a little confused. Your code is already retrieving the path and file
selected by the user (saveFileDialog1.FileName). So all you have to do is
the following:

this.Text = saveFileDialog1.FileName;

Of course this string includes the path and extension as well. If you want
to extract path, file name, and extension separately you can use the
FileInfo class:

FileInfo fi = new FileInfo(saveFileDialog1.FileName);

Then you can use the properties of the FileInfo object to retrieve the
information you want:

fi.DirectoryName \\ the directory's full path
fi.Name \\ the file name
fi.Extension \\ the file extension

Hope this helps.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.

"Csharper95" <rk*****@hotmail-dot-com.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
I want to get the file name and path from a SaveFileDialog (for a
'save as' operation) after the user has saved the information under a
new file name (and presumably under a new path) ?

I want to display the new file name and path in the Form.text Title.
So how do I go about getting the info ?

Heres my code:
private void menu_profile_saveas_Click(object sender,
System.EventArgs e)
{
//Open file for reading
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = geoData.GetFilePath();
saveFileDialog1.Filter = "DAT31-8 Files
(*.N31)|*.n31|All Files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true ;
//read and filter the raw data
if(saveFileDialog1.ShowDialog() ==
DialogResult.OK)
{
geoData.SaveToN31File(saveFileDialog1.FileName);

}

}

Could someone please help ?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 16 '05 #2
Or you can use:

Path.GetDirectoryName(saveFileDialog1.FileName);
Path.GetFileName(saveFileDialog1.FileName);
Path.GetExtension(saveFileDialog1.FileName);

No need to create a FileInfo object this way, not like it should be that
expensive.

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"Kai Brinkmann [MSFT]" <ka******@online.microsoft.com> wrote in message
news:O4**************@TK2MSFTNGP14.phx.gbl...
I'm a little confused. Your code is already retrieving the path and file
selected by the user (saveFileDialog1.FileName). So all you have to do is
the following:

this.Text = saveFileDialog1.FileName;

Of course this string includes the path and extension as well. If you want
to extract path, file name, and extension separately you can use the
FileInfo class:

FileInfo fi = new FileInfo(saveFileDialog1.FileName);

Then you can use the properties of the FileInfo object to retrieve the
information you want:

fi.DirectoryName \\ the directory's full path
fi.Name \\ the file name
fi.Extension \\ the file extension

Hope this helps.
--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Csharper95" <rk*****@hotmail-dot-com.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
I want to get the file name and path from a SaveFileDialog (for a
'save as' operation) after the user has saved the information under a
new file name (and presumably under a new path) ?

I want to display the new file name and path in the Form.text Title.
So how do I go about getting the info ?

Heres my code:
private void menu_profile_saveas_Click(object sender,
System.EventArgs e)
{
//Open file for reading
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = geoData.GetFilePath();
saveFileDialog1.Filter = "DAT31-8 Files
(*.N31)|*.n31|All Files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true ;
//read and filter the raw data
if(saveFileDialog1.ShowDialog() ==
DialogResult.OK)
{
geoData.SaveToN31File(saveFileDialog1.FileName);

}

}

Could someone please help ?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: strauss.sean | last post by:
Hi! I am trying to import a query (as a table) from a database (MS Access) in a specified drive, path, and filename; the filename and path is being stored in a table for easy reconfiguration. ...
0
by: Brian Burgess | last post by:
Hi all, Anyone know to get the full path name of a file dragged from an Outlook message? I can get the filename itself so far, without the path. For Outlook 2000 I know the path would be...
11
by: cdkorzen | last post by:
I'm sorry if this is a rehash, but all I see is the same info. Here's my debacle: I CAN get the PATH_INFO to work. With ANYTHING but ASP. Python, Perl, Cmd files... works fine. ASP can't...
7
by: pedagani | last post by:
Dear comp.lang.c++, I'm trying to read a file with very long filename using ifstream. Although, the file exists the file open for read fails. Is there a restriction on the size? I'm using winXP...
10
by: wo_shi_big_stomach | last post by:
Newbie to python writing a script to recurse a directory tree and delete the first line of a file if it contains a given string. I get the same error on a Mac running OS X 10.4.8 and FreeBSD 6.1. ...
7
by: ApexData | last post by:
Hello I currently Link the FE/BE using the LinkTables Option and the Linked Table Manager. Any time I need to move the BE to another location, I have to go through this process over again. I...
3
by: sherifffruitfly | last post by:
This is the best I could quickly come up with: (?<path>:\\(?:+\\)+)(?<filename>.+?\.+) It's certainly too permissive, but I don't *think* it leaves any valid ones out (I'm sure a...
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
18
by: Aaron Gray | last post by:
Has anyone got a code snippet to separate out the path components, ie drive, path, filename, and extension ? Many thanks in advance, Aaron
18
by: RedLars | last post by:
Hi, How can check using .NET 1.1 that a string contains a valid filename for winxp? The application in question has a textbox where user can enter filename and only the filename. It should...
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...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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,...
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.