8

In WinRT there is no FileInfo class, only a StorageFile class.

How can I get the size of a file using the StorageFile class?

MBender
  • 5,395
  • 1
  • 42
  • 69
Yang
  • 825
  • 1
  • 10
  • 13

3 Answers3

12

So here you go:


storageFile.getBasicPropertiesAsync().then(
    function (basicProperties) {
        var size  = basicProperties.size;
    }
);
Vahid Farahmand
  • 2,528
  • 2
  • 14
  • 20
11

In C#:

StorageFile file = await openPicker.PickSingleFileAsync();
BasicProperties pro = await file.GetBasicPropertiesAsync();
if (pro.Size != 0){}

You should using Windows.Storage.FileProperties for BasicProperties.

Bos
  • 365
  • 2
  • 13
0

Have you tried this:

        create_task(file->GetBasicPropertiesAsync()).then([this, file](BasicProperties^ basicProperties)
        {
            String^ dateModifiedString = dateFormat->Format(basicProperties->DateModified) + " " + timeFormat->Format(basicProperties->DateModified);
            OutputTextBlock->Text += "\nFile size: " + basicProperties->Size.ToString() + " bytes" + "\nDate modified: " + dateModifiedString;

        });

See: http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileproperties.basicproperties.size.aspx

Vahid Farahmand
  • 2,528
  • 2
  • 14
  • 20