【发布时间】:2015-12-30 07:30:11
【问题描述】:
我想在单击 Windows 窗体中的按钮时在资源文件中现有数据的末尾添加数据。 我有一个带有 3 个文本框的窗体 -
text_box1: Name
text_box2: Value
text_box3: Comments
and a button named as Save.
按钮代码:
private void button1_Click(object sender, EventArgs e)
{
myMethod.Create(textBox1.Text, textBox2.Text, textBox3.Text);
}
在资源文件中添加数据的方法:
public class myMethod
{
public static void Create(string myName, string myValue, string myComment)
{
try
{
ResXResourceReader resxReader = new ResXResourceReader(@"D:\Validator_Tool\resx\resx\myres.resx");
resxReader.UseResXDataNodes = true;
IDictionaryEnumerator data = resxReader.GetEnumerator();
while (data.MoveNext())
{
ResXResourceWriter resxWriter = new ResXResourceWriter(@"D:\Validator_Tool\resx\resx\myres.resx");
var node = new ResXDataNode(myName, myValue);
node.Comment = myValue;
resxWriter.AddResource(node);
resxWriter.Close();
}
}
catch (FileNotFoundException caught)
{
MessageBox.Show("Source: " + caught.Source + " Message: " + caught.Message);
}
}
}
请帮助我解决这个问题,在资源文件中添加数据,因为使用此代码,我的数据将被现有数据覆盖,但我希望我的数据应附加在现有数据的末尾。 这段代码在使用 IDictionaryEnumerator 异常时也给了我异常是:
System.InvalidOperationException
【问题讨论】: