×
Namespaces

Variants
Actions
(Difference between revisions)

How to check for available storage space on Windows Phone

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
hamishwillee (Talk | contribs)
m (Hamishwillee -)
 
Line 1: Line 1:
[[Category:Windows Phone]][[Category:Windows Phone 8]][[Category:Windows Phone 7.5]][[Category:Files/Data on Windows Phone]][[Category:How To]]
+
[[Category:Files/Data on Windows Phone]][[Category:How To]][[Category:Code Snippet]][[Category:Windows Phone 8]][[Category:Windows Phone 7.5]][[Category:XAML]]
 
{{Abstract|This code snippet shows how to check whether a Windows Phone app has enough space to store its data using [http://msdn.microsoft.com/en-au/library/system.io.isolatedstorage.isolatedstoragefile.aspx IsolatedStorageFile].}}
 
{{Abstract|This code snippet shows how to check whether a Windows Phone app has enough space to store its data using [http://msdn.microsoft.com/en-au/library/system.io.isolatedstorage.isolatedstoragefile.aspx IsolatedStorageFile].}}
{{UnderConstruction|}}
 
 
{{Tip|While {{Icode|IsolatedStorageFile}} works in Windows Phone 7 and 8, if you're focussing on Windows Phone 8 only you should use the new API - see [http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj681698(v=vs.105).aspx Quickstart: Working with files and folders in Windows Phone 8]}}
 
{{Tip|While {{Icode|IsolatedStorageFile}} works in Windows Phone 7 and 8, if you're focussing on Windows Phone 8 only you should use the new API - see [http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj681698(v=vs.105).aspx Quickstart: Working with files and folders in Windows Phone 8]}}
  

Latest revision as of 12:03, 28 June 2013

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

[edit] 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).

[edit] References

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

This page was last modified on 28 June 2013, at 12:03.
59 page views in the last 30 days.
×