Clearing file content with XmlWriter
Last post 05-12-2008 12:11 PM by pbrooks. 1 replies.
Sort Posts:
05-12-2008 12:06 AM
Clearing file content with XmlWriter

Is there a way to clear out a file using XmlWriter before writing the final content and without having to first delete the file?

brettr

Joined on 12-07-2006
Seattle
Posts 69
05-12-2008 12:11 PM
Marked as Answer
Re: Clearing file content with XmlWriter

 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();
}

If this has answered your question, please click on "Mark as Answer" on this post.

Thanks,
Page Brooks, MCSD, MCAD
PageBrooks.com | RSS Feed

pbrooks

Joined on 03-23-2006
Florence, SC
Posts 116