•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 425,926 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,686 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 11684 | Replies: 3
![]() |
•
•
Join Date: Jun 2006
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
I have an application that saves some data in xml document.
The user can add a new data to xml document.
The problem is the old data will be overwritten by the new one,How could I solve that??
Here is my code for that method which still needs "APPENDING":
The user can add a new data to xml document.
The problem is the old data will be overwritten by the new one,How could I solve that??
Here is my code for that method which still needs "APPENDING":
XmlTextWriter textWritter=new XmlTextWriter("F:/Documents and Settings/Administrator/Desktop/Account.xml", null); textWritter.WriteStartDocument(); textWritter.WriteStartElement("USER"); //User nametextWritter.WriteStartElement("UserName",""); textWritter.WriteString(txtUsrName.Text.Trim()); textWritter.WriteEndElement(); //Email textWritter.WriteStartElement("Email",""); textWritter.WriteString(txtEmail.Text.Trim()); textWritter.WriteEndElement(); textWritter.WriteEndDocument(); textWritter.Close();
try this.
it creates its own file stream and sets the access to append.
it replaces your fiest line
it creates its own file stream and sets the access to append.
it replaces your fiest line
Stream xmlFile = new FileStream(@"c:\path",FileMode.Append);
XmlTextWriter textWritter = new XmlTextWriter(xmlFile, Encoding.Default); Last edited by plazmo : Aug 25th, 2006 at 10:57 am.
Hi,
If you have a specific XML schema, you can use a DataSet not bound to a database or connection and provide your own schema. This way you can use all data bound controls and table cursors and at the end you can load/save the whole dataset back as XML.
Loren Soth
If you have a specific XML schema, you can use a DataSet not bound to a database or connection and provide your own schema. This way you can use all data bound controls and table cursors and at the end you can load/save the whole dataset back as XML.
Loren Soth
Crimson K. Software _________________________________________________________________ Crimson K. Blog
•
•
Join Date: Jun 2006
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
First thanks all for your time & help.
I've found out another easier way to solve my problem.
About checking whether the file is already existed or not there is static method in "system.IO" called "File.Exist" ,which check whether te file is already existed or not.
About the appending Problem ,I've used "XmlDocument" class
inorder to use some methods in it .
The result'll be like that:
</USERS>
<User>
<UserName>Buggaya</UserName>
<Email>Buggaya@gmail.com</Email>
</User>
</USERS>
Here's my code :
I've found out another easier way to solve my problem.
About checking whether the file is already existed or not there is static method in "system.IO" called "File.Exist" ,which check whether te file is already existed or not.
About the appending Problem ,I've used "XmlDocument" class
inorder to use some methods in it .
The result'll be like that:
</USERS>
<User>
<UserName>Buggaya</UserName>
<Email>Buggaya@gmail.com</Email>
</User>
</USERS>
Here's my code :
if(!File.Exists("F:/Documents and Settings/Administrator/Desktop/Account.xml")) { XmlTextWriter textWritter=new XmlTextWriter("F:/Documents and Settings/Administrator/Desktop/Account.xml", null); textWritter.WriteStartDocument(); textWritter.WriteStartElement("USERS"); textWritter.WriteEndElement(); textWritter.Close(); } XmlDocument xmlDoc=new XmlDocument(); xmlDoc.Load("F:/Documents and Settings/Administrator/Desktop/Account.xml"); XmlElement subRoot=xmlDoc.CreateElement("User"); //UserName XmlElement appendedElementUsername=xmlDoc.CreateElement("UserName"); XmlText xmlTextUserName=xmlDoc.CreateTextNode(txtUsrName.Text.Trim()); appendedElementUsername.AppendChild(xmlTextUserName); subRoot.AppendChild(appendedElementUsername); xmlDoc.DocumentElement.AppendChild(subRoot); //Email XmlElement appendedElementEmail=xmlDoc.CreateElement("Email"); XmlText xmlTextEmail=xmlDoc.CreateTextNode(txtEmail.Text.Trim()); appendedElementEmail.AppendChild(xmlTextEmail); subRoot.AppendChild(appendedElementEmail); xmlDoc.DocumentElement.AppendChild(subRoot); xmlDoc.Save("F:/Documents and Settings/Administrator/Desktop/Account.xml");
![]() |
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- [urgent] HTML form => XML file (JSP)
- Parse an XML document with AJAX (JavaScript / DHTML / AJAX)
- Searching and Comparing strings from an XML Document (Python)
- Database table convert to xml document to cache (VB.NET)
- append to XML file (Visual Basic 4 / 5 / 6)
- problem reading xml file in c# (C#)
Other Threads in the C# Forum
- Previous Thread: Accesing controls on the form from custom method
- Next Thread: firewall application


Linear Mode