How to stop overwriteprompt when creating SaveFileDialog using GetSaveFileName

走远了吗. 提交于 2019-12-11 07:03:27

问题


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


回答1:


Try this:

SaveFileDialog dialog = new SaveFileDialog();
dialog.OverwritePrompt = false; //Removes warning
dialog.ShowDialog();



回答2:


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




回答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.




回答4:


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;




回答5:


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.




回答6:


You can set OverwritePrompt property to false like so:

 SaveFileDialog dialog = new SaveFileDialog();
 dialog.OverwritePrompt = false;
 dialog.ShowDialog();


来源:https://stackoverflow.com/questions/5512752/how-to-stop-overwriteprompt-when-creating-savefiledialog-using-getsavefilename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!