How to stop overwriteprompt when creating SaveFileDialog using GetSaveFileName

I want to stop the file replacement dialog from popping up in SaveFileDialog by calling the Windows API method. I just want to do this because I am creating a new folder with the file name given by the user, so using another file with the same name is not a question ...

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

thanks

+1
c # savefiledialog
source share
6 answers

In fact, I could finally find a solution to my question, and I would like to post it here, as I think it might be useful to someone ...

When creating SaveFileDialog using the GetSaveFileName Windows function, we must send a link to the OPENFILENAME structure (we will consider it as fromn), which contains the information necessary to create savefiledialog. In this structure, we must set flags for what we need, therefore, if we want to stop the rewrite request, we should not set a flag for it:

The flag value must be in .Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOTESTFILECREATE | OFN_ENABLEHOOK | OFN_HIDEREADONLY;

instead

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

+2
source share

Try the following:

SaveFileDialog dialog = new SaveFileDialog(); dialog.OverwritePrompt = false; //Removes warning dialog.ShowDialog(); 
+2
source share

I will update this if I misunderstood what you are asking (and I'm sorry if I have, if you provide my current code. But you can do:

 yourSaveFileDialog.OverwritePrompt = false; 

to suppress rewriting invitations

+2
source share

It seems to me that you really want the user to select a folder, then to fill it with files. In this case you should use FolderBrowserDialog. It was designed to allow the user to select a folder.

+1
source share

From the .NET SDK:

Class SaveFileDialog

...

The properties

...

OverwritePrompt - Gets or sets a value that indicates a warning is displayed in the Save As dialog box if the user specifies a file name that already exists.

You can set the property of your dialog box to false to disable rewriting requests.

0
source share

You can set the OverwritePrompt property to false as follows:

  SaveFileDialog dialog = new SaveFileDialog(); dialog.OverwritePrompt = false; dialog.ShowDialog(); 
0
source share

All Articles