M
msnews.microsoft.com
Hi,
I am using System.Windows.Forms.SaveFileDialog to prompt the user to select a file to which data is exported.
I would like the control to always add the default extension, in this case .xls, to whatever filename the user enters - but the default behavior is that the extension is only added if the user has not already entered an extension.
E.g. if the user types in the filename "export.txt" then the SaveFileDialog should append .xls to form "export.txt.xls".
Of course I could just do this manually after the user has OK'd but then the dialog's prompt for create and overwrite won't be correct.
How can I configure SaveFileDialog to ALWAYS append .xls?
Below is a code snippet that I use to prompt the user for a filename:
public static string GetExportFilename()
{
System.Windows.Forms.SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.DefaultExt = "*.xls";
saveFileDialog.Filter = "Excel 8.0+ (*.xls)|*.xls";
saveFileDialog.AddExtension = true;
saveFileDialog.CheckPathExists = true;
saveFileDialog.CheckFileExists = false;
saveFileDialog.CreatePrompt = true;
saveFileDialog.OverwritePrompt = true;
string exportFilename = "";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
exportFilename = saveFileDialog.FileName;
}
return exportFilename;
}
Regards
Joubert
I am using System.Windows.Forms.SaveFileDialog to prompt the user to select a file to which data is exported.
I would like the control to always add the default extension, in this case .xls, to whatever filename the user enters - but the default behavior is that the extension is only added if the user has not already entered an extension.
E.g. if the user types in the filename "export.txt" then the SaveFileDialog should append .xls to form "export.txt.xls".
Of course I could just do this manually after the user has OK'd but then the dialog's prompt for create and overwrite won't be correct.
How can I configure SaveFileDialog to ALWAYS append .xls?
Below is a code snippet that I use to prompt the user for a filename:
public static string GetExportFilename()
{
System.Windows.Forms.SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.DefaultExt = "*.xls";
saveFileDialog.Filter = "Excel 8.0+ (*.xls)|*.xls";
saveFileDialog.AddExtension = true;
saveFileDialog.CheckPathExists = true;
saveFileDialog.CheckFileExists = false;
saveFileDialog.CreatePrompt = true;
saveFileDialog.OverwritePrompt = true;
string exportFilename = "";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
exportFilename = saveFileDialog.FileName;
}
return exportFilename;
}
Regards
Joubert