0
我想在窗体中单击按钮时在资源文件中现有数据的末尾添加数据。 我有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
感谢您的帮助 – VIVEK
我已经使用此代码,但与此代码我的评论已删除形式上一个条目。 – VIVEK
我认为当您尝试从阅读器使用相同的文件创建一个作家时,这会引发异常。 – rdongart