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
If the user clicks Yes, the size is increased.
Tweet
No comments:
Post a Comment