I've an application that needs saving data from datagrid into an XML file.
Currently, it is working only half way coz the file keeps saving the data to the original file. Which means, it is appended to the bottom of the .XML but it repeats the root element.
I'ld like to eliminate this problem, but couldn't go about it.
Any suggestion?
I think my current code is a little low-level, so hopefully, there's a more efficient method.

Thanks,
Ika
P.S: I've inserted screen shots of the before and after of the .xml file when new data is inserted.
******


Sam HobbsPosted Jan 14, 2010, 11:56 AM
Then in your program you can read the existing data in, then add the new data, then write that out. If you write the data out to the same file that you read from, then call dispose on the stream you use to read the data; otherwise you might get a sharing violation trying to write to the file.
I don't know how to do that using XmlTextWriter. You might need to convert your code to use XmlText. I suggest converting your code to use XmlDocument. Load the XML using XmlDocument.Load and then get the root using GetElementsByTagName. Then append the new data to the XmlNodeList. You can get more help with XmlDocument by searching the articles in this web site for XmlDocument; go to this web site's home page and search the articles from there.
Sam HobbsPosted Jan 27, 2010, 9:37 PM
Ika AJPosted Jan 27, 2010, 9:30 PM
Ika AJPosted Jan 14, 2010, 4:00 AM
Sam HobbsPosted Jan 13, 2010, 11:47 AM
Sam HobbsPosted Jan 12, 2010, 9:43 PM