I want to add data at the end of existing data in resource file on the click of button in windows form. I have a windows form with 3 text boxes -
text_box1: Name
text_box2: Value
text_box3: Comments
and a button named as Save.
code for button:
private void button1_Click(object sender, EventArgs e)
{
myMethod.Create(textBox1.Text, textBox2.Text, textBox3.Text);
}
Method to add data in resource file:
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);
}
}
}
Please help me in this problem to add data in resource file because with this code my data is overwrite with existing data but I want my data should append at the end of the existing data. This code giving me exception too while using IDictionaryEnumerator exception is:
System.InvalidOperationException