Isolated Storage in the Silverlight Application

Published on
10,497 Points
2 Endorsements
Last Modified:
Microsoft gives a good definition in .NET Framework Developer's Guide for Isolated Storage  :

Isolated storage is a data storage mechanism that provides isolation and safety by defining standardized ways of associating code with saved data. Standardization provides other benefits as well. Administrators can use tools designed to manipulate isolated storage to configure file storage space, set security policies, and delete unused data. With isolated storage, your code no longer needs unique paths to specify safe locations in the file system and data is protected from other applications that only have isolated storage access.

For more information on Isolated Storage Visit here

How to increase the space of the issolatedStorage of the application
Steps To Test The Current Space for the application

1. Run any Silverlight Application.
Right click on it will show you the Silverlight button. Click on it

2. Now the Silverlight properties Dialog will appear
Now select the Application Storage Tab It will show you the Application storage for all the Silverlight applications on the system

Siverlight Configuration
3. Create an application with the name "IsolatedStorageApp".
You can name it as per your choice. I will be using this in my example application.
Add New Silverlight control and name it as "IncreaseIsolatedStorage.xaml"


4. Right-click on the IsolatedStorageApp in the solution explorer.
     1. Choose Add
     2. New Item
     3. Silverlight User Control. In the Name box rename it to IncreaseIsolatedStorage


5. Display space textblocks
For our purpose we are only taking three textblocks to display Space Used, Space Available, Current Quota and the textbox for the New Space request. Add the following lines in the .xaml file

<Canvas Canvas.Left="10" Canvas.Top="10"> 
    <TextBlock Canvas.Left="10" x:Name="SpacedUsed" >Current Spaced Used=</TextBlock> 
    <TextBlock Canvas.Left="10" x:Name="SpaceAvaiable" Canvas.Top="20">Current Space Available=</TextBlock> 
    <TextBlock Canvas.Left="10" x:Name="CurrentQuota" Canvas.Top="40">Current Quota=</TextBlock> 
    <TextBlock Canvas.Left="10" x:Name="NewSpace" Canvas.Top="70">New space (in bytes) to request=</TextBlock> 
    <TextBox Canvas.Left="255" Canvas.Top="70" Width="100" x:Name="SpaceRequest"></TextBox> 
    <TextBlock Canvas.Left="365" Canvas.Top="70" Width="60">(1048576 = 1 MB)</TextBlock> 
    <Button Canvas.Left="10" Content="Increase Storage" Canvas.Top="100" Width="100" Height="50" Click="Button_Click"></Button> 
    <TextBlock Canvas.Left="10" Canvas.Top="160" x:Name="Result"></TextBlock> 

Open in new window

Now our page will look like:


6. GetStorageData
To set The Values of the Three TextBlocks lets create a function GetStorageData and call it in the constructor.
private void GetStorageData() 
    //creating an object for the IsolatedStorageFile 
    using (IsolatedStorageFile MyAppStore = solatedStorageFile.GetUserStoreForApplication()) 
        //calculating the space used 
        SpacedUsed.Text = "Current Spaced Used = " + (MyAppStore.Quota - MyAppStore.AvailableFreeSpace).ToString() + " bytes"; 
        //getting the AvailableFreeSpace 
        SpaceAvaiable.Text = "Current Space Available=" + MyAppStore.AvailableFreeSpace.ToString() + " bytes"; 
        //getting the Current Quota CurrentQuota.Text = "Current Quota=" + MyAppStore.Quota.ToString() + " bytes"; 

Open in new window

Here we will be missing a namespace "System.IO.IsolatedStorage" So need to include it.

7. Now the function to increase the quota

/// <summary> 
/// Increases the Isolated Storage Space of the current Application 
/// </summary> /// 
<param name="spaceRequest"> Total Space Requested to increase</param> 
private void IncreaseStorage(long spaceRequest) 
    //creating an object for the IsolatedStorageFile for current Application 
    using (IsolatedStorageFile MyAppStore = solatedStorageFile.GetUserStoreForApplication()) 
        //Calculating the new space long newSpace = MyAppStore.Quota + spaceRequest; 
            //displays a message box for the increase request. 
            //if accepted by the user then displays the result as quota increased 
            //else unsuccessful. 
            if (true == MyAppStore.IncreaseQuotaTo(newSpace)) 
                Result.Text = "Quota successfully increased."; 
                Result.Text = "Quota increase was unsuccessfull."; 
        catch (Exception e) 
            Result.Text = "An error occured: " + e.Message; 
        //recalculate the static 

Handling the button event 

private void Button_Click(object sender, RoutedEventArgs e) 
        //taking the space request in the long variable 
        long spaceRequest = Convert.ToInt64(SpaceRequest.Text); 
        //calling the function to increase the space 
        Result.Text = "Bad Data Entered by the user"; 

Open in new window

Run the Application and click on the Button after filling the textbox with the desired space to increase. A Dialog box will appear for the confirmation click yes to see the results.


Thanks and Regards

Meetu Choudhary

My Web || My Fourm
Download Code

1 Comment
LVL 54

Expert Comment

by:Mark Wills
Thanks Meetu,

I have a few thoughts on where I would like to use Isolated Storage in my own applications...

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Join & Write a Comment

This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Check How effective MS Exchange Expert thinks Exchange Mailbox Recovery by SysTools IS. Visit the Official site to get detailed information:- https://www.systoolsgroup.com/exchange-recovery.html (https://www.systoolsgroup.com/exchange-recovery.h…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month