473,394 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

to append and existing file and read the same

Use the method InsertAfter() from the XmlDocument class or
AppendChild from XmlNode class. Here is a short example to
use InsertAfter().

http://weblogs.asp.net/sonukapoor/articles/132854.aspx

Sonu Kapoor
Blog: http://weblogs.asp.net/sonukapoor/

-----Original Message-----
(Type your message here)

--------------------------------
From: Lalit Dubey

Hi I use the following code to append an file and read the same but it is overwriting in the file without
appending it ::

// this was to creat the xml file and append it Sring XmlFile="Data.xml;
System.IO.DirectoryInfo directoryInfo;
System.IO.DirectoryInfo directoryXML;

directoryInfo = System.IO.Directory.GetParent (Application.StartupPath);
if (directoryInfo.Name.ToString() == "bin")
{
directoryXML = System.IO.Directory.GetParent (directoryInfo.FullName);XmlFile = directoryXML.FullName + "\\" + "Data.xml";
}
else
{
XmlFile = directoryInfo.FullName + "\\" + "Data.xml"}
XmlTextWriter XmlWtr = new System.Xml.XmlTextWriter (XmlFile,null);
XmlWtr.Formatting=Formatting.Indented;
XmlWtr.WriteStartDocument();
XmlWtr.WriteStartElement("emplyees");
XmlWtr.WriteStartElement("emplyee");
XmlWtr.WriteElementString("empID", empid.Text);
XmlWtr.WriteElementString("name", empname.Text);
XmlWtr.WriteElementString("age", empage.Text);
XmlWtr.WriteElementString("level", level.SelectedItem.ToString());XmlWtr.WriteElementString("salary", empsalary.Text);
XmlWtr.WriteEndElement();
XmlWtr.WriteStartElement("emplyee");
XmlWtr.WriteElementString("empID", "35");
XmlWtr.WriteElementString("name", "kumar");
XmlWtr.WriteElementString("age", "34");
XmlWtr.WriteElementString("level", "Leader");
XmlWtr.WriteElementString("salary", "220000");
XmlWtr.WriteEndElement();
XmlWtr.WriteEndElement();
XmlWtr.WriteEndDocument();
XmlWtr.Flush();
XmlWtr.Close();

it is over-writing the file again and and again

////then i write to read it

textBox1.visible=true
XmlTextReader XmlRdr = new System.Xml.XmlTextReader (XmlFile);while(XmlRdr.Read())
{
if(Rdr.NodeType==XmlNodeType.Element&&XmlRdr.Name =="name")
{
textbox1.text= XmlRdr.ReadString() + "\r\n";

}

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>E+Ak789Z4Em5+Ofwc2J7tg==</Id>
.

Nov 12 '05 #1
0 2691

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: V.Boomessh | last post by:
Hai All I am developing a VB application in .NET. I read a encrypted text file which contains details of SQL Server name, SQL DBName etc... for DB Connection and i prepare a connection string...
0
by: msnews.microsoft.com | last post by:
Hi, I am trying to use below code to write .NET resource files. What I am expecting is to append items to an exsiting file. But any time below code just remove exsting items and just write the...
2
by: sm | last post by:
How to "Insert" (not append) new text segment to an existing text file? Assume that we have text file as shown below; Elvis Sofia Kylix BCB--> How to insert here? Atten BuilderX Roma
2
by: Nico Grubert | last post by:
Hi there, I would like to open an existing file that contains some lines of text in order to append a new line at the end of the content. My first try was: >>> f = open('/tmp/myfile', 'w')...
3
by: Cc | last post by:
how do i delete last append line?
1
by: Ritesh Raj Sarraf | last post by:
Hi, I've got a problem here. def compress_the_file(zip_file_name, files_to_compress, sSourceDir): """ Condenses all the files into one single file for easy transfer """ try:
3
by: blackd77 | last post by:
What I would LIKE to do is noted in the subject line. What I'm finding is that "edit SQL" appears to only be an option if I am creating a table. If I select "append to" the option to edit SQL...
1
by: Curious | last post by:
I want to write to an output file, "C:\\temp\\debug.txt": If the file exists, append the new content to the end of the file (instead of overwriting the current content). If the file doesn't exist,...
2
by: Curious | last post by:
I want to write to an output file, "C:\\temp\\debug.txt": If the file exists, append the new content to the end of the file (instead of overwriting the current content). Therefore, I want to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.