SaveFileDialog Class
Assembly: System.Windows.Forms (in system.windows.forms.dll)
This class can either open and overwrite an existing file or create a new file.
Most of the functionality for this class is found in the FileDialog class.
Windows Mobile 2003 for Pocket PC, Windows Mobile 2003 for Smartphone, Windows CE Platform Note: On the Pocket PC, if you do not specify a file name extension, the control appends the extension of the selected type from the dialog box. On Windows CE, the control does not append an extension. All platforms support the FilterIndex property, which returns the index of the selected extension filter.
The following code example illustrates creating a SaveFileDialog, setting members, calling the dialog box using the ShowDialog method, and saving the current file. The example requires a form with a button placed on it.
private void button1_Click(object sender, System.EventArgs e) { Stream myStream ; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ; saveFileDialog1.FilterIndex = 2 ; saveFileDialog1.RestoreDirectory = true ; if(saveFileDialog1.ShowDialog() == DialogResult.OK) { if((myStream = saveFileDialog1.OpenFile()) != null) { // Code to write the stream goes here. myStream.Close(); } } }
protected void button1_Click(Object sender, System.EventArgs e)
{
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.set_Filter(
"txt files (*.txt)|*.txt|All files (*.*)|*.*");
saveFileDialog1.set_FilterIndex(2);
saveFileDialog1.set_RestoreDirectory(true);
if (saveFileDialog1.ShowDialog() == get_DialogResult().OK) {
if ((myStream = saveFileDialog1.OpenFile()) != null) {
// Code to write the stream goes here.
myStream.Close();
}
}
} //button1_Click
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.CommonDialog
System.Windows.Forms.FileDialog
System.Windows.Forms.SaveFileDialog
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.