Add data at the end of existing data in resource file
<p>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 -</p><pre><br /><code>text_box1: Name<br />text_box2: Value<br />text_box3: Comments<br />and a button named as Save.<br /></code><br /></pre><p>code for button:</p><pre><br /><code> private void button1_Click(object sender, EventArgs e)<br /> {<br /> myMethod.Create(textBox1.Text, textBox2.Text, textBox3.Text);<br /> }<br /></code><br /></pre><p>Method to add data in resource file:</p><pre><br /><code>public class myMethod<br /> {<br /> public static void Create(string myName, string myValue, string myComment)<br /> {<br /> try<br /> {<br /> ResXResourceReader resxReader = new ResXResourceReader(@"D:\Validator_Tool\resx\resx\myres.resx");<br /> resxReader.UseResXDataNodes = true;<br /> IDictionaryEnumerator data = resxReader.GetEnumerator();<br /><br /> while (data.MoveNext())<br /> {<br /> ResXResourceWriter resxWriter = new ResXResourceWriter(@"D:\Validator_Tool\resx\resx\myres.resx");<br /> var node = new ResXDataNode(myName, myValue);<br /> node.Comment = myValue;<br /> resxWriter.AddResource(node);<br /> resxWriter.Close();<br /> }<br /><br /> }<br /> catch (FileNotFoundException caught)<br /> {<br /> MessageBox.Show("Source: " + caught.Source + " Message: " + caught.Message);<br /> }<br /> }<br /> }<br /></code><br /></pre><p>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:</p><blockquote><p>System.InvalidOperationException</p></blockquote><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34524947/add-data-at-the-end-of-existing-data-in-resource-file">http://ift.tt/1mhPzYt</a></h2>
Nhận xét
Đăng nhận xét