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

Retrieve the selected folder and entered file name from SaveFileDialog

P: n/a
Hi,

I want to retrieve the selected folder and entered file name from the
SaveFilsDialog. The user is able to create or selected a different
folder during the dialog displayed. If user enters "a/b/c/d" in the
"File name:" box, then the SaveFileDialog.FileName will return
"Path\a\b\c\d" as the name.

Is there any way to just retrieve the selected folder and entered file
name form the SaveFiledialog?

Thanks in advance.

Allen

Apr 10 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a

Hi,

You can create a FileInfo object.

FileInfo f = new FileInfo( SaveFileDialog.File);
string directoryName = f.DirectoryName;
string fileName = f.Name;

Hope this helps!

Apr 10 '06 #2

P: n/a
Hi,

I don't quite understand your example, but you can use Path.GetDirectoryName
and Path.GetFilename to get them.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Allen" <al******@gmail.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
Hi,

I want to retrieve the selected folder and entered file name from the
SaveFilsDialog. The user is able to create or selected a different
folder during the dialog displayed. If user enters "a/b/c/d" in the
"File name:" box, then the SaveFileDialog.FileName will return
"Path\a\b\c\d" as the name.

Is there any way to just retrieve the selected folder and entered file
name form the SaveFiledialog?

Thanks in advance.

Allen

Apr 10 '06 #3

P: n/a
I want to validate the entered filename. So, I set the SaveFiledialog
ValidateNames property to false and register the event handler for
FileOK.
However, the FileName property returned from SaveFileDialog contains
the full path with the filename. Here is the actual case that I want to
catch:

1.
Selected folder: C:\Temp
File name entered: a\b
FileName is : C:\Temp\a\b

2.
Selected folder: C:\Temp
File name entered: a/b
FileName is : C:\Temp\a/b

Although these inputs will be rejected by the system. Because I set
ValidateNames to false, I won't see the error message from system.
Thus, I would like to get the exact file name entered by the user, so I
can validate the entered text.

Does anyone know how to retrieve the actual text entered by the user
from the SaveFileDialog?

Thanks.
Allen

Apr 11 '06 #4

P: n/a
I do not think there is a way to get only the filename from the
SaveFileDialog.
Why don't you set the ValidateNames property to 'true'? Wouldn't this
do exactly what you are trying to do?

If you still would like to validate the filename yourself, you can use
one of the solutions presented above.
If you only want to validate the filename then I you can use the Path
class ( look at the suggestion in a previous post).

If you also want to do read/write operations on the file, then the
FileInfo class may be a good option ( look in the API or my first post).

Apr 11 '06 #5

P: n/a
I do not think there is a way to get only the filename from the
SaveFileDialog.
Why don't you set the ValidateNames property to 'true'? Wouldn't this
do exactly what you are trying to do?

If you still would like to validate the filename yourself, you can use
one of the solutions presented above.
If you only want to validate the filename then I you can use the Path
class ( look at the suggestion in a previous post).

If you also want to do read/write operations on the file, then the
FileInfo class may be a good option ( look in the API or my first post).

Apr 11 '06 #6

P: n/a
Thanks for your help.

Allen

Apr 11 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.