1
我想保存一个新的文件名,但现在我只能保存重写文件。每次我尝试保存新文件名时,都会出现一个消息框,其中包含警告对话框:SaveFileDialog - (文件路径)不存在。验证是否给出了正确的文件名
(文件路径)不存在。验证正确的文件名 给。”
下面是我的代码,任何人都可以请指出缺少什么?谢谢。
private void button5_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Title = "Save File";
saveFileDialog1.CheckFileExists = true;
saveFileDialog1.CheckPathExists = true;
saveFileDialog1.Filter = "Text files (*.txt)|*.txt| CONF(*.conf)|*.conf|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName != "")
{
// Saves the Image via a FileStream created by the OpenFile method.
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile();
// Saves the Image in the appropriate ImageFormat based upon the
// File type selected in the dialog box.
// NOTE that the FilterIndex property is one-based.
switch (saveFileDialog1.FilterIndex)
{
case 1:
saveFileDialog1.FileName = saveFileDialog1.FileName + ".txt";
break;
case 2:
saveFileDialog1.FileName = saveFileDialog1.FileName + ".conf";
break;
default:
saveFileDialog1.FileName = saveFileDialog1.FileName + ".txt";
break;
}
fs.Close();
}
}
谢谢!我现在能够保存文件。 – Firzanah