Friday, April 16, 2010

IsolatedStorageFile in Silverlight


Recently I was stuck over a problem of writing on the user's permanent storage using a silverlight application. With microsoft trying to give more security to the user by not allowing the silverlight application to write to a location of developers choice, surely the developers are left struggling with their desire to access the users hard-drive.

Silverlight has restricted the use of the most famous techniques of writing a file to the client's machine : namely Filestream and Streamwriter. On the contrary it has provided the developers with an alternative called IsolatedStorageFile. This class is part of the System.IO package.

Isolated storage reserves a location on the user's machine that microsoft considers to be safe. It resides in the Documents and settings folder of your OS partition. Initially a size of 1 mb is provided where data can be written. This size can be increased by using the IsolatedStorage.IncreaseQuotaTo(int noOfBytes). But one should remember that this statement will request the user to grant permission for the same. This has been done to provide increased security to the user. I would prefer that you use this location whenever you want to store less data like the passwords, user data etc. Here's an example to create an isolatedstorage to write a file in it.


No comments:

Post a Comment