All about WP7 Isolated Storage - Recommendations and Best Practices
published on: 6/14/2011 | Views: N/A | Tags: IsoStore BestPractices
by WindowsPhoneGeek
This is the 11th article from the "All about WP7 Isolated Storage " series of short articles focused on real practical examples with source code rather than a plain theory. I am going to talk about recommendations and best practices when using Isolated Storage in Windows Phone 7.
- All about WP7 Isolated Storage - intro to Isolated Storage
- All about WP7 Isolated Storage - Creating Folders and files
- All about WP7 Isolated Storage - Store data in IsolatedStorageSettings
- All about WP7 Isolated Storage - Read and Save Text files
- All about WP7 Isolated Storage - Read and Save XML files using XmlSerializer
- All about WP7 Isolated Storage - Read and Save XML files using XmlWriter
- All about WP7 Isolated Storage - Read and Save Images
- All about WP7 Isolated Storage - Read and Save Captured Image
- All about WP7 Isolated Storage - Read and Save Binary files
- All about WP7 Isolated Storage - File manipulations
- All about WP7 Isolated Storage - Recommendations and Best Practices
- All about WP7 Isolated Storage - Open Source Databases and Helper Libraries
To begin with lets first mention the key things you need to consider when using Isolated Storage.
6 Things you need to consider when using Isolated Storage
-
1. "Isolated" storage means that your application can not share any data with another application. If you need two applications to use the same data, then that data can't be local to either of them. Instead, you can use a web service and store the data on the web. Once your data is stored in the cloud, it can be accessed by as many applications you want.
-
2. When an application is updated in Windows Phone Marketplace, its isolated storage folder is not modified. So if you change the data in Isolated Storage when upgrading your app to a new version, it is up to you to upgrade and modify your files so that the new version is working properly.
-
3. IsolatedStorageSettings is not thread-safe and can throw IsolatedStorageException if used simultaneously from multiple threads.
-
4. When a WP7 application is uninstalled, its isolated storage data will be deleted.
-
5. Stored resources on a phone are limited.
-
6. When a Windows Phone has only 10 percent of its storage space remaining, the user receives a status notification.
Best Practices
-
If using Directories always check if the Directory exists otherwise an exception could happen.
-
A directory must be empty before it is deleted. The deleted directory cannot be recovered once deleted.
-
It is a common practice to use try{}catch{} when working with the Isolated Storage to prevent any unexpected exception to be seen by the user.
-
When working with files always use Using statement because it provides a convenient syntax that ensures the correct use of IDisposable objects.
-
When working with files always check if the Directory in which you want to create/delete a File exists.
-
Check for existing file before trying to read it
-
All Key/Value pairs in the IsolatedStorageSettings must be unique pairs, so before saving any value to the settings make sure that it has a unique key.
-
Make sure that you have cleared all temporary data in Isolated Storage in case this data will no longer be used(usually upon application exit). A good practice is to create a temporary cache folder that you can clear.
-
Make sure that users are enabled to delete any new data they have created. For example if users can generate files using your app they have to be able to delete these files as well.
-
Do not save important values like passwords as a plain text. Always try to encrypt them.
Another Helpful Resources you can take a look for reference:
- MSDN: Isolated Storage Overview for Windows Phone: the official MSDN documentation
- How many files are too many files for isolated storage(Performance)? by Mick N.
I hope that the post was helpful. Stay tuned for the rest of the WindowsPhoneGeek.com content.
You can also follow us on Twitter @winphonegeek
Comments
Interesting post
posted by: Peter Smith on 6/14/2011 5:42:42 PM
Very helpful info. I did not know about most of the limitation that IsolatedStorage has.
Update new version to the Marketplace
posted by: Rahmed Kumar on 6/14/2011 5:47:25 PM
Finally I understood why it is called "Isolated Storage". Just have a question.
What happens if I do not change my Isolated Storage data when upgrading to the new version? I mean I want to publish a new version to the Marketplace but do I have to reset/change the storage? I did not change anything related to the data only the UI is changed?
@Kumar
posted by: Gian on 6/14/2011 11:35:28 PM
All the data you saved to the Isolated Storage of your app remains among different updates of your app. Updating the app does not delete the files. You could end up with the opposite problem tho : your version needs to use a new datamodel and you've to support or auto-upgrade older version :)
@Gian
posted by: Rahmed Kumar on 6/15/2011 12:02:14 AM
Thank you so much for answering my question.
Our Top Articles & Free books
- Our FREE e-book: "Windows Phone Toolkit In Depth" 2nd edition
- 400+ Windows Phone Development articles in our Article Index
- 21 WP7 Toolkit in Depth articles covering all controls
- 12 WP7 Coding4Fun Toolkit in Depth articles covering all controls
- Performance Tips when creating WP7 apps
- Creating a WP7 Custom Control in 7 Steps
- WP7 working with VisualStates: How to make a ToggleSwitch from CheckBox
- What makes a WP7 App successful
- Creating theme friendly UI in WP7 using OpacityMask
- Implementing Windows Phone 7 DataTemplateSelector and CustomDataTemplateSelector
- All about Splash Screens in WP7 – Creating animated Splash Screen
- Getting Started with Unit Testing in Silverlight for WP7
- WP7 WatermarkedTextBox custom control
Our Top Tips & Samples
- All about WP7 Isolated Storage series
- WP7 Dynamically Generating DataTemplate in code
- 5 tips for a successful WP7 Marketplace submission
- WP7: Navigating to a page in different assembly
- WP7 ContextMenu: answers to popular questions
- WP7 ListBox: answers to popular questions
- WP7 working with Images: Content vs Resource build action
- WP7 Element Binding samples
- WP7 working with XML: reading, filtering and databinding
- Drawing in WP7: #2 Drawing shapes with finger
- WP7 TextBox Light theme problems - the solution
- Changing the WP7 Panorama Background Image dynamically with Animation
