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

Dulini Atapattu
  • 2,735
  • 8
  • 33
  • 47
  • Care to show what you've got so far? – SeeSharp Apr 01 '11 at 11:46
  • 1
    If it's prompting you to replace the file, then the existence of another file with the same name, IS, the matter. – Bob G Apr 01 '11 at 11:46
  • 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... thanks – Dulini Atapattu Apr 01 '11 at 11:49
  • Actually I create savefiledialog using Windows function - GetSaveFileName coz I have customized the dialog using hookProc... pls answer if anyone knows... – Dulini Atapattu Apr 02 '11 at 08:57

6 Answers6

4

Try this:

SaveFileDialog dialog = new SaveFileDialog();
dialog.OverwritePrompt = false; //Removes warning
dialog.ShowDialog();
Marcin Deptuła
  • 11,789
  • 2
  • 33
  • 41
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

SeeSharp
  • 2,760
  • 16
  • 15
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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
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;

Dulini Atapattu
  • 2,735
  • 8
  • 33
  • 47
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.

Thalur
  • 1,155
  • 9
  • 13
0

You can set OverwritePrompt property to false like so:

 SaveFileDialog dialog = new SaveFileDialog();
 dialog.OverwritePrompt = false;
 dialog.ShowDialog();
Vale
  • 3,258
  • 2
  • 27
  • 43
  • @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 folder – Vale Apr 01 '11 at 11:56