I am trying to save a file with a double-dot extension. But whenever I do that the file ends up with the extension doubled in my case I choose to save as .lmk.ilu
extension but then the file ends up as filename.lmk.ilu.lmk.ilu
Here`s the code:
public static bool BrowseForFileToSave(BrowserInfo info, IWin32Window owner, string title)
{
var dlg = new SaveFileDialog
{
OverwritePrompt = info.OverwritePrompt,
DefaultExt = info.DefaultExt,
Filter = info.Filter,
FilterIndex = info.FilterIndex,
FileName = info.FileName,
InitialDirectory =
info.UseLastFolderAsInitialDirectory && BrowserInfo.LastFolder != null
? BrowserInfo.LastFolder
: info.InitialDirectory
};
if (title != null)
dlg.Title = title;
if(info.FileNameValidationCallback != null)
dlg.FileOk += info.FileNameValidationCallback;
var result = dlg.ShowDialog(owner);
if (result == DialogResult.OK)
{
BrowserInfo.LastFolder = Path.GetDirectoryName(dlg.FileName);
info.FileName = dlg.FileName;
return true;
}
return false;
}
Everything is fine when debugging up to
var result = dlg.ShowDialog(owner);
Up to this point dlg.FileName is null. Then after the dialog operations finish the name is already with four extensions instead of two.
How can I make it have only two extensions when I choose two extensions, given that single dot extensions work fine, and that SupportMultiDottedExtensions = true
didn`t help?
Edit:
Save File Dialog , restrict name
I implemented the File.Ok name validation but it works once the "Save" button is pressed.
How can I validate extensions on selecting an option from the "Save as type" dropdown, i.e. before the dialog is closed?