Tamir Dresher

Getting the Free Storage Space in WinRT

16 Dec 2014

This post was originally published on 16 Dec 2014 at http://blogs.microsoft.co.il/iblogger/2014/12/16/getting-free-storage-space-winrt/

I didnt find any documenation to this method other than the thread in StackOverflow: http://stackoverflow.com/questions/19510449/disk-space-in-winrt-using-c-sharp-in-windows-8

so im keeping it here so it wont get lost by the winds of timeā€¦.

public static async Task<UInt64> GetFreeSpace(this IStorageItem sf)
{
    var properties = await sf.GetBasicPropertiesAsync();
    var filteredProperties = await properties.RetrievePropertiesAsync(new[] { "System.FreeSpace" });
    var freeSpace = filteredProperties["System.FreeSpace"];
    return (UInt64)freeSpace;
}

Sample use:

var freeSpace = await ApplicationData.Current.LocalFolder.GetFreeSpace();
Debug.WriteLine(freeSpace.GetSizeString());

Thank you  Filip Skakun