我想使用 SaveFileDialog 控件保存文件。为什么文件需要已经存在才能保存?
这是我正在使用的代码:
string month = dateTimePicker1.Value.Month.ToString();
string year = dateTimePicker1.Value.Year.ToString();
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = @"C:\";
saveFileDialog1.Title = "Save Sql Files";
saveFileDialog1.FileName = "MysqlBackup-"+month+"-"+year+".sql";
saveFileDialog1.CheckFileExists = true;
saveFileDialog1.DefaultExt = "Sql";
saveFileDialog1.Filter = "Sql files (*.Sql)|*.Sql";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
// Here is the error. After typing in the filename, when I click OK it gives me an error stating that the file does not exist.
}