我想要将文件保存到C驱动器,用户将选择任何位置来保存文件。我已经尝试了下面的代码,它给我一个粗体的错误。请你纠正我是错的。我也想在保存之前检查文件是否存在。我怎样才能做到这一点?如何将资源文件(resx)保存到驱动器
这是错误我得到验证正确的路径给出
string PathSelection = "";
if (PathSelection.Length > 0)
{
txtInputfile.Text = PathSelection;
}
// i tried this
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = saveFileDialog1.FileName;
saveFileDialog1.Title = "Save Resource Files";
saveFileDialog1.CheckFileExists = true;
saveFileDialog1.CheckPathExists = true;
saveFileDialog1.DefaultExt = "resx";
saveFileDialog1.Filter = "Save Resource Files (*.resx)|*.resx";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK) // error here!
{
PathSelection = saveFileDialog1.FileName;
//string path = saveFileDialog1.FileName;
oDataSet.WriteXml(PathSelection);
}
oDataSet.Tables.Add("Data");
什么是错误? – 2015-02-09 09:56:02
错误:验证是否给出了正确的路径 – 2015-02-09 09:56:33
您是否在您的类中添加了“使用System.Windows.Forms;'指令? – 2015-02-09 09:56:48