Increase Isolated Storage Quota in Silverlight

Silverlight provides a mechanism called Isolated Storage to store data on the client computer. This mechanism is provided to ensure a safe browsing experience, as your application cannot directly access the user’s local file system. So in order to persist data like application state or user settings/preferences, you use a virtual file system called Isolated Storage.

The default quota for isolated storage is 1MB. However for Silverlight Out-Of-Browser applications, the default quota is 25MB. If you are making use of the Isolated Storage very frequently, you may find that even 25 MB is not sufficient.

The good part is that you can increase these limits if the user approves it. This is done by calling the IncreaseQuotaTo method of the IsolatedStorageFile class. Let us see how

First add a reference to the System.IO.IsolatedStorage namespace. Now write the following code on a button click event

// Increase Isolates Storage by DevCurry.com
private void btnIncreaseIso_Click(object sender, RoutedEventArgs e)
{
using (IsolatedStorageFile isof = IsolatedStorageFile
.GetUserStoreForApplication())
{
Int64 freeSpace = isof.AvailableFreeSpace;
Int64 needSpace = 20971520; // 20 MB in bytes
if (freeSpace < needSpace)
{
if (!isof.IncreaseQuotaTo(isof.Quota + needSpace))
{
MessageBox.Show("User rejected increase space request");
}
else
{
MessageBox.Show("Space Increased");
}
}
}
}

First a store isolated for user is retrieved in the isof variable. The IncreaseQuotaTo method accepts a parameter which takes the number of bytes you want to increase. When the user clicks the button, Silverlight displays a message box which shows the current usage of the application in the isolated storage and the new size requested

Silverlight Isolated Storage

If the user clicks Yes, the size is increased.



Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: