Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Clearing file content with XmlWriter
1 replies. Latest Post by pbrooks on May 12, 2008.
(0)
brettr
Member
119 points
123 Posts
05-12-2008 12:06 AM |
Is there a way to clear out a file using XmlWriter before writing the final content and without having to first delete the file?
pbrooks
Contributor
2671 points
355 Posts
05-12-2008 12:11 PM |
brettr,
You could open the file in Truncate mode to clear the file while opening. However, I believe this will only work if the file already exists. See the code below:
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("test.xml", FileMode.Truncate, isoStore)){ XmlWriter w = XmlWriter.Create(isoStream); w.WriteStartElement("Test"); w.WriteRaw("Stuff"); w.WriteEndElement(); w.Flush(); isoStream.Flush(); isoStream.Close();}