/// <summary> /// Raises the <see cref="VistaFileDialog.FileOk" /> event. /// </summary> /// <param name="e">A <see cref="System.ComponentModel.CancelEventArgs" /> that contains the event data.</param> protected override void OnFileOk(CancelEventArgs e) { // For reasons unknown, .Net puts the OFN_FILEMUSTEXIST and OFN_CREATEPROMPT flags on the save file dialog despite // the fact that these flags only works on open file dialogs, and then prompts manually. Similarly, the // FOS_CREATEPROMPT and FOS_FILEMUSTEXIST flags don't actually work on IFileSaveDialog, so we have to implement // the prompt manually. if (DownlevelDialog == null) { if (CheckFileExists && !File.Exists(FileName)) { PromptUser(ComDlgResources.FormatString(ComDlgResources.ComDlgResourceId.FileNotFound, Path.GetFileName(FileName)), MessageBoxButton.OK, MessageBoxImage.Exclamation, MessageBoxResult.OK); e.Cancel = true; return; } if (CreatePrompt && !File.Exists(FileName)) { if (!PromptUser(ComDlgResources.FormatString(ComDlgResources.ComDlgResourceId.CreatePrompt, Path.GetFileName(FileName)), MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No)) { e.Cancel = true; return; } } } base.OnFileOk(e); }