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

Retrieve the selected folder and entered file name from SaveFileDialog

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
6 9152

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
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
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
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
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
Thanks for your help.

Allen

Apr 11 '06 #7

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

Similar topics

13
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be...
3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
1
by: BillZondlo | last post by:
HI, I'm using saveFileDialog to get or make a file to save my stirngs to. saveFileDialog1.Filter = "txt files (*.txt)|*.txt" ; //display dialog saveFileDialog1.FilterIndex = 2 ;...
0
by: george_Martinho | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a...
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
3
by: Nayan | last post by:
Hi, I am trying to download a file from website, and to get the local file name form the user, I am using SaveFileDialog. I apply the filter (I parse the url to get the file name and assign)...
1
by: =?Utf-8?B?U29waGll?= | last post by:
Hi, I have a button for user to click and specify a folder destination, not file name, for example: "C:\foldername1", and this path will appear to a text box. How do I do it by using...
1
by: The Mad Ape | last post by:
Hello I have a FileSave Dialog and am trying to pass the current folder name to a string. Is there any way to do that? It was easy to get the file path and name using .FileName but I see nothing...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.