Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to check for available storage space on Windows Phone

From Wiki
Jump to: navigation, search

This code snippet shows how to check whether a Windows Phone app has enough space to store its data using IsolatedStorageFile.

Tip.pngTip: While IsolatedStorageFile works in Windows Phone 7 and 8, if you're focussing on Windows Phone 8 only you should use the new API - see Quickstart: Working with files and folders in Windows Phone 8

Overview

Applications that write data to permanent storage can potentially fail due to out of (storage) memory errors. A well designed application should check for space before writing.

public void CheckDiskSpace(long neededSpace)
{
using (IsolatedStorageFile myISFile = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myISFile.AvailableFreeSpace < neededSpace) // if true, means there is no space available in the phone.
{
throw new Exception("No space available on the phone, please delete a file");
}
}
}

Tip.pngTip: YOu might be tempted to set a quota for your app using IsolatedStorageFile.IncreaseQuotaTo(). Note that "Windows Phone apps are not restricted to a particular quota; they should make careful use of storage based on their app scenario requirements" (MSDN documentation).

References

This question originated in the discussion boards: Handle low storage space condition

This page was last modified on 28 June 2013, at 09:03.
56 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×