C#利用SaveFileDialog实现保存的功能示例
private void tsmExportLog_Click(object sender, EventArgs e)
{
try
{
String title = "导出日志";
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = String.Format("{0}(*.txt)|*.txt", "日志");
saveFileDialog.FilterIndex = 2;
saveFileDialog.RestoreDirectory = true;
saveFileDialog.Title = title;
saveFileDialog.FileName = DateTime.Now.ToString("yyyyMMdd");
saveFileDialog.DefaultExt = "txt";
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string targetFilePath = "C:\\AA.txt";
File.Copy(targetFilePath, saveFileDialog.FileName);
MessageBox.Show("导出成功!");
}
}
catch (Exception ex)
{
MessageBox.Show("导出失败!");
}
}