Allow selection of readonly files from SaveFileDialog?
- by Andy Dent
I'm using Microsoft.Win32.SaveFileDialog in an app where all files are saved as readonly but the user needs to be able to choose existing files. The existing files being replaced are renamed eg: blah.png becomes blah.png-0.bak, blah.png-1.bak and so on.
Thus, the language for the OverwritePrompt is inappropriate - we are not allowing them to overwrite files - so I'm setting dlog.OverwritePrompt = false;
The initial filenames for the dialog are generated based on document values so for them, it's easy - we rename the candidate file in advance and if the user cancels or chooses a different name, rename it back again.
When I delivered the feature, testers swiftly complained because they wanted to repeatedly save files with names different from the agreed workflow (those goofy, playful guys!).
I can't figure out a way to do this with the standard dialogs, in a way that will run safely on both XP (for now) and Windows 7.
I was hoping to hook into the FileOK event but that is called after I get a warning dialog:
|-----------------------------------------|
| blah.png |
| This file is set to read-only. |
| Try again with a different file name. |
|-----------------------------------------|