How to stop overwriteprompt when creating SaveFileDialog using GetSaveFileName
Asked Answered
M

6

0

I want to stop popping of file replace dialog at SaveFileDialog using Windows API method calls. I just want to do this because I create a new folder with the file name given by the user, thus exsistance of another file with the same name is not a matter...

Actually I create savefiledialog using Windows function - GetSaveFileName coz I have customized the dialog using hookProc... pls answer if anyone knows...

Thanks

Mount answered 1/4, 2011 at 11:31 Comment(4)
Care to show what you've got so far?Matland
If it's prompting you to replace the file, then the existence of another file with the same name, IS, the matter.Adz
No, actually I want to create a folder with the file name the user has given because I have to save number of files (different modes according to my app) and it s better to save them in a folder... thanksMount
Actually I create savefiledialog using Windows function - GetSaveFileName coz I have customized the dialog using hookProc... pls answer if anyone knows...Mount
M
2

Actually I could finally find the solution for my question and I would like to place it here as I think it may be useful to someone...

When creating the SaveFileDialog using GetSaveFileName Windows function, we have to send a reference to an OPENFILENAME struct (consider it as ofn) which contains details required to create the savefiledialog. In this struct, we have to set flags for what we need, thus if we want to stop the overwrite prompt, we should not set a flag for it:

The flag setting should be ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOTESTFILECREATE | OFN_ENABLEHOOK | OFN_HIDEREADONLY;

instead of

ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOTESTFILECREATE | OFN_ENABLEHOOK | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;

Mount answered 2/4, 2011 at 15:15 Comment(0)
B
4

Try this:

SaveFileDialog dialog = new SaveFileDialog();
dialog.OverwritePrompt = false; //Removes warning
dialog.ShowDialog();
Barbie answered 1/4, 2011 at 11:46 Comment(0)
M
3

I'll update this if I've misunderstood what you're asking (and I'm sorry if I have if you provide your current code. But, you can do:

yourSaveFileDialog.OverwritePrompt = false;

to suppress overwrite prompts

Matland answered 1/4, 2011 at 11:47 Comment(0)
L
3

Sounds to me that you actually want the user to pick the folder so you can then fill it with files. In which case you should use FolderBrowserDialog. It was designed to let the user choose a folder.

Lettering answered 1/4, 2011 at 12:32 Comment(0)
M
2

Actually I could finally find the solution for my question and I would like to place it here as I think it may be useful to someone...

When creating the SaveFileDialog using GetSaveFileName Windows function, we have to send a reference to an OPENFILENAME struct (consider it as ofn) which contains details required to create the savefiledialog. In this struct, we have to set flags for what we need, thus if we want to stop the overwrite prompt, we should not set a flag for it:

The flag setting should be ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOTESTFILECREATE | OFN_ENABLEHOOK | OFN_HIDEREADONLY;

instead of

ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOTESTFILECREATE | OFN_ENABLEHOOK | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;

Mount answered 2/4, 2011 at 15:15 Comment(0)
B
0

From the .NET SDK:

SaveFileDialog Class

...

Properties

...

OverwritePrompt - Gets or sets a value indicating whether the Save As dialog box displays a warning if the user specifies a file name that already exists.

You can set the property of your dialog to false to disable overwrite prompts.

Berry answered 1/4, 2011 at 11:46 Comment(0)
P
0

You can set OverwritePrompt property to false like so:

 SaveFileDialog dialog = new SaveFileDialog();
 dialog.OverwritePrompt = false;
 dialog.ShowDialog();
Paquito answered 1/4, 2011 at 11:51 Comment(1)
@dia You CAN have same file and folder names, so replace dialog should not pop up. Check if you already have same filenames in that folderPaquito

© 2022 - 2024 — McMap. All rights reserved.