I am using the SaveFileDialog
in WPF to export into excel file at particular loaction selected by user. But in between when SaveFileDailog
is opened then user clilks on Cancel button
on dialog then i am getting the another dialog that says "Do you want to save changes you made to 'Sheet1'?"
and then "Export completed"
instead of cancelling to export.
So what i have to do to tackle with it? Any thing in WPF something like 'DialogResult'
that is same as in winForms?
SaveFileDialog will return true if user saved (the ShowDialog
method returns a nullable bool), and return false/null if user pressed cancel. Below is a sample MSDN code to get you started:
// Configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension
// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
// Save document
string filename = dlg.FileName;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With