none
Clearing StorageFile Content

    Question

  • Yes, this should be simple... but not seen a way to do this.

    How can you clear the contents from a StorageFile?  Is there an apprpriate Method to call?

    I'm talking about the actual data in a specific File, not clearing all data like using the ClearAsync Method.

    Thanks

    Thursday, November 29, 2012 8:50 PM

Answers

  • I could not find the Stream.Size.  This works below...

    StorageFile myFile = await myFolder.GetFileAsync("myFile.txt");

    await FileIO.WriteTextAsync(myFile, "");

    • Marked as answer by shaggygi Friday, November 30, 2012 2:21 PM
    Friday, November 30, 2012 2:21 PM

All replies

  • Stream.Size = 0

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Thursday, November 29, 2012 9:24 PM
  • I could not find the Stream.Size.  This works below...

    StorageFile myFile = await myFolder.GetFileAsync("myFile.txt");

    await FileIO.WriteTextAsync(myFile, "");

    • Marked as answer by shaggygi Friday, November 30, 2012 2:21 PM
    Friday, November 30, 2012 2:21 PM
  • This worked for me:

                    using (var stream = await File.OpenStreamForWriteAsync())
                    {
                        stream.SetLength(0);
    .
    .
    .
                    }

    Where File is the StorageFile you opened.

    Tuesday, March 11, 2014 6:21 AM