如何将资源文件(resx)保存到目录 [英] How to Save resource file(resx) to a directory

查看:100
本文介绍了如何将资源文件(resx)保存到目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我想将文件保存到C盘,用户将选择任何位置来保存文件。我在下面尝试了这个代码,它在粗线上给我一个错误。可以请你纠正我错了。我还想在保存之前检查文件是否存在。我怎样才能做到这一点?



这是我得到的错误验证是否给出了正确的路径





Hi Everyone.

I want save a file to C drive, the user will select any locations to save the file. i have tried this code below and it is giving me an error on the line in bold. can you please correct me were am wrong. i also want to check if the file exist before saving. how can i do that?

this is the error am getting verify that the correct path was given


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");

推荐答案

您的源代码中有一些奇怪的东西,但它有效,我没有任何错误!



你需要解决的问题是:



There are some strange things in your source code but it works, I've not got any errors!

The things you need to fix are:

string PathSelection = "";
// You have not initialized PathSelection, why shall its length > 0?
//if (PathSelection.Length > 0)
{
    //txtInputfile.Text = PathSelection;
}
// i tried this
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
// FileName has not been initialized!
//saveFileDialog1.InitialDirectory = saveFileDialog1.FileName;


这篇关于如何将资源文件(resx)保存到目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆