Csharp/C Sharp/GUI Windows Form/SaveFileDialog
Содержание
Call ShowDialog method to show the dialog
using System;
using System.Windows.Forms;
class MainClass {
static void Main(string[] args) {
SaveFileDialog dlg = new SaveFileDialog();
if (dlg.ShowDialog() == DialogResult.OK) {
Console.WriteLine(dlg.FileName);
}
}
}
Set CheckFileExists to true
using System;
using System.Windows.Forms;
class MainClass {
static void Main(string[] args) {
SaveFileDialog dlg = new SaveFileDialog();
dlg.CheckFileExists = true;
if (dlg.ShowDialog() == DialogResult.OK) {
Console.WriteLine(dlg.FileName);
}
}
}
Set InitialDirectory for SaveFileDialog
using System;
using System.Windows.Forms;
class MainClass {
static void Main(string[] args) {
SaveFileDialog dlg = new SaveFileDialog();
dlg.InitialDirectory = Application.StartupPath;
if (dlg.ShowDialog() == DialogResult.OK) {
Console.WriteLine(dlg.FileName);
}
}
}
Use Filter in SaveFileDialog to filter file extension
using System;
using System.Windows.Forms;
class MainClass {
static void Main(string[] args) {
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "RichText Files (*.rtf)|*.RTF|Text Files (*.txt)|*.TXT" +
"|All files (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK) {
Console.WriteLine(dlg.FileName);
}
}
}