Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XMLDocument

Status
Not open for further replies.

kyern

Programmer
Mar 30, 2006
36
US
I am using the following code to write the contents of one xml file to another, the code is just being indented so it is easier to read. Is there any way to modify this so that it can write to the same file? I know it can't write directly because there is a lock, but I tried to duplicate the code and reverse the file names but it still tells me there is a lock. Any help would be greatly appreciated.

David

Code:
 void IndentXML() {
		string filePath = @"c:\file\nc.xml";
		
		XmlDocument doc = new XmlDocument();
					doc.Load(@"c:\file\nc2.xml");
		
		XmlTextWriter writer = new XmlTextWriter(filePath2,Encoding.UTF8);
					  writer.Formatting = Formatting.Indented;
					  writer.Indentation = 4;
					  
		doc.WriteTo(writer);

		writer.Flush();
		writer.Close();
    }
 
Give this a try...

Code:
System.IO.FileStream FS = New System.IO.FileStream(filePath, System.IO.FileMode.Append)

XmlTextWriter writer = New XmlTextWriter(FS, System.Text.Encoding.Unicode)

Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top