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

时间:2013-01-05 03:59:29

标签: c# filesize winrt-async

在WinRT中,没有FileInfo类,只有StorageFile类。

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

3 个答案:

答案 0 :(得分:11)

在C#中:

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

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

答案 1 :(得分:10)

所以你走了:


storageFile.getBasicPropertiesAsync().then(
    function (basicProperties) {
        var size  = basicProperties.size;
    }
);

答案 2 :(得分:0)

你试过这个:

        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;

        });

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