我想要將文件保存到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