<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>
</Canvas>
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";
}
}
Here we will be missing a namespace "System.IO.IsolatedStorage
/// <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;
try
{
//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.";
}
else
{
Result.Text = "Quota increase was unsuccessfull.";
}
}
catch (Exception e)
{
Result.Text = "An error occured: " + e.Message;
}
//recalculate the static
GetStorageData();
}
}
Handling the button event
private void Button_Click(object sender, RoutedEventArgs e)
{
try
{
//taking the space request in the long variable
long spaceRequest = Convert.ToInt64(SpaceRequest.Text);
//calling the function to increase the space
IncreaseStorage(spaceRequest);
}
catch
{
Result.Text = "Bad Data Entered by the user";
}
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (1)
Commented:
I have a few thoughts on where I would like to use Isolated Storage in my own applications...