private void btnSave_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Text Files (*.txt)|*.txt"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { string fileName = saveFileDialog.FileName; // Save file code here } }
SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Image Files (*.jpg, *.png)|*.jpg;*.png"; saveFileDialog.ShowDialog();In this example, a SaveFileDialog is used to prompt the user to select a file to save as either a .jpg or .png image file. The dialog box is displayed using the ShowDialog method. The System.Windows.Forms SaveFileDialog ShowDialog method is part of the .NET Framework class library.