PeppeJ
PeppeJ

Reputation: 643

Force Save File Dialog to save with a specific string as file name

Hi I'm wondering if there's anyway to force a user to save a file with a specific name.

For instance I know you can do:

SaveFileDialog.FileName = "string";

But now I wonder if I can lock FileName, so that the user can not change it. Since for a software I'm making it's crucial that the FileName is equal to the, (Because it loads the name of the file and enters it as the title of a TextBox).

string Title;

Upvotes: 4

Views: 3323

Answers (2)

Adam Houldsworth
Adam Houldsworth

Reputation: 64527

Well, if all you need is for them to pick a directory then you don't need the SaveFileDialog and can instead use the FolderBrowserDialog to at least let them choose where it goes.

Of course you don't need to use the file name that the user enters into the SaveFileDialog, the dialog does nothing special other than let the user pick a location, file name, and type. Any and all information entered into this form by the user can be ignored by your code... which is obviously a little pointless.

From a usability perspective, using the save dialog will set user expectations at being in control of the location, type and file name (at least). Presenting just the folder browser and informing them the name is fixed (with error checking for files that happen to have this name), should hopefully mean the user won't expect to control the file name.

Of course, if the user doesn't even need to control the location, go the whole nine yards and automate that too, perhaps using Isolated Storage or a file buried in the install path of your app.

Upvotes: 11

Daniel
Daniel

Reputation: 6775

As Adam said above, you could just use a FolderBrowserDialog instead of a SaveFileDialog. If for some reason you really want to use SaveFileDialog, you can just set FileName = "string"; in your Ok button click handler. I would not recommend doing that, though, as it would do something that the user is not expecting.

Upvotes: 2

Related Questions