gpt4 book ai didi

c# - SaveFileDialog -(文件路径)不存在。验证是否给出了正确的文件名

转载 作者:太空宇宙 更新时间:2023-11-03 21:00:03 25 4
gpt4 key购买 nike

我想保存一个新的文件名,但现在我只能保存重写文件。每次我尝试保存新文件名时,都会出现一个带有警告对话框的消息框:

(File path) does not exist. Verify that the correct file name was given."

下面是我的代码,谁能指出遗漏了什么?谢谢。

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();
}
}

最佳答案

你需要设置CheckFileExistsCheckPathExists为 false 以防止对话框检查文件是否存在,否则如果用户指定路径,对话框将显示警告:

saveFileDialog1.CheckFileExists = false;
saveFileDialog1.CheckPathExists = false;

关于c# - SaveFileDialog -(文件路径)不存在。验证是否给出了正确的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46355599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com