How many of you want to check the available free space in your Windows Phone device? It is very simple to get the details from the settings page. But think about a case where you want to check the free space from your app and want to chose some logic to notify the user.

 

In this small but useful post, we will discuss about the API and will share a small piece of code, which will allow you to know the available free space in user’s phone device.

 

The sealed class named “IsolatedStorageFile” available under the namespace “System.IO.IsolatedStorage” provides you a static method “GetUserStoreForApplication()” which allows you to obtain user-scoped isolated storage for use by an application. The IsolatedStorageFile instance has a property called “AvailableFreeSpace” which returns a long value representing the amount of free space available in the phone storage. The unit of the returned value is bytes. From this value, you can easily calculate the free space in Kilo Bytes (KB), Mega Bytes (MB) and/or Giga Bytes (GB).

 

Here is the complete code that you might want to reference to use in your application:

 

using (var isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
    var sizeInBytes = isolatedStorageFile.AvailableFreeSpace;
    var sizeInKB = sizeInBytes / 1024.0;
    var sizeInMB = sizeInKB / 1024.0;
    var sizeInGB = sizeInMB / 1024.0;
    
    MessageBox.Show(string.Format("Available Free Space: {0} GB", Math.Round(sizeInGB, 2)));
}

 

Here you can see that, first we are getting the instance of user’s isolated store by calling the static method of the sealed class named IsolatedStorageFile.GetUserStoreForApplication() and the calling the AvailableFreeSpace property to get the free space information.

 

Here is what you will see after calculating the byte unit to GB :

 

How to retrieve Free Space details in Windows Phone?

 

I hope, this simple tip will help you to retrieve the available free storage space in your application/game and then ask the user to take some steps based on your business requirement.

 

Thanks a lot for visiting my blog. Subscribe to my blog’s RSS feed or newsletter to get the article updates directly in your inbox. I am also available in Twitter and Facebook. Connect with me to get regular updates on technical posts. Happy coding!!!

 

Have a question? Or, a comment? Let's Discuss it below...

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.