如何在WinRT中获取文件大小?

Yan*_*ang 8 c# filesize winrt-async

在WinRT中没有FileInfo类,只有一个StorageFile类.

如何使用StorageFile该类获取文件的大小?

Vah*_*and 11

所以你走了:


storageFile.getBasicPropertiesAsync().then(
    function (basicProperties) {
        var size  = basicProperties.size;
    }
);
Run Code Online (Sandbox Code Playgroud)


Bos*_*Bos 11

在C#中:

StorageFile file = await openPicker.PickSingleFileAsync();
BasicProperties pro = await file.GetBasicPropertiesAsync();
if (pro.Size != 0){}
Run Code Online (Sandbox Code Playgroud)

您应该使用Windows.Storage.FileProperties for BasicProperties.