locked
Check if file is empty or size 0 under local storage in windows 8.1 application using C#

    Question

  • How to check if file is empty in C# for a windows 8.1 application?

    I did try Fileinfo but it doesn't seem to be supported in windows 8.1 applications.

    Wednesday, July 9, 2014 11:27 AM

Answers

All replies

  • Open file to StorageFile object. Then get basic properties of the file via StorageFile.GetBasicPropertiesAsync method. You can check the file size by BasicProperties.Size property.

    Reference:

    MSDN forum: How can I get a file's size


    • Edited by Bo Song Wednesday, July 9, 2014 1:29 PM
    • Marked as answer by Mahagh Thursday, July 17, 2014 8:19 AM
    Wednesday, July 9, 2014 1:29 PM
  • I did try this. But it is giving always size=0 even when file isn't.
    Friday, July 11, 2014 6:56 AM
  • Hi,

    When I use the codes in my project:

    StorageFile file = await Windows.Storage.KnownFolders
         .PicturesLibrary.GetFileAsync("test.txt");
                BasicProperties basicProperties = await file.GetBasicPropertiesAsync();
                var Size = basicProperties.Size;

    I can get right file size whennever the file is empty or not. If the file is empty, the file size is zero. If the file is not empty, I can get the right file size.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Thursday, July 17, 2014 8:54 AM