Creating a file quota bar associated with the user's isolated storage area : IsolatedStorage « Data « Silverlight






Creating a file quota bar associated with the user's isolated storage area

Creating a file quota bar associated with the user's isolated storage area
    


<UserControl x:Class='SilverlightApplication3.MainPage'
    xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
    xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
    xmlns:d='http://schemas.microsoft.com/expression/blend/2008' 
    xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' 
    mc:Ignorable='d' 
    d:DesignWidth='640' 
    d:DesignHeight='480'>

    <Canvas x:Name="LayoutRoot" Background="White">
        <Rectangle x:Name="maximumRectangle" Width="1" Height="20" Fill="#FFFFFFFF" Stroke="#FF000000" Canvas.Left="1" Canvas.Top="5" RadiusX="5" RadiusY="5"/>
        <Rectangle x:Name="currentRectangle" Width="1" Height="20" Stroke="#FF000000" Canvas.Left="1" Canvas.Top="5" RadiusX="5" RadiusY="5" StrokeThickness="0">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1.35" StartPoint="0.5,-0.3">
                    <GradientStop Color="#FF54CDEA" Offset="0"/>
                    <GradientStop Color="#FF017328" Offset="0.5"/>
                    <GradientStop Color="#FF54CDEA" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
    </Canvas>
</UserControl>


//File: Page.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.IO.IsolatedStorage;
using System.Text;

namespace SilverlightApplication3
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            using (IsolatedStorageFile isoFile =  IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isoFile.FileExists("binaryFile1"))
                    isoFile.DeleteFile("binaryFile1");
                    
                Random random = new Random();
                int size = random.Next(Convert.ToInt32(isoFile.Quota)-1);
                string randomString = CreateRandomString(size);

                IsolatedStorageFileStream fileStream = isoFile.CreateFile("binaryFile1");
                byte[] bytes = System.Text.Encoding.Unicode.GetBytes(randomString);
                fileStream.Write(bytes, 0, randomString.Length);
                fileStream.Close();

                double usedSpace = isoFile.Quota - isoFile.AvailableFreeSpace;        
                maximumRectangle.Width = (isoFile.Quota / 10024) * 2;                 
                currentRectangle.Width = (usedSpace / 10024) * 2;                     
            }
        }

        private string CreateRandomString(int size)
        {
            StringBuilder builder = new StringBuilder();
            Random random = new Random();
            
            char c;
            for (int i = 0; i < size; i++)
            {
                c = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                builder.Append(c);
            }
            return builder.ToString();
        }
    }
}

   
    
    
    
  








Related examples in the same category

1.IsolatedStorage DemoIsolatedStorage Demo
2.Removing items from the isolated storage areaRemoving items from the isolated storage area
3.Creating a directory within the isolated storage areaCreating a directory within the isolated storage area
4.Creating subdirectories within the isolated storage areaCreating subdirectories within the isolated storage area
5.Asks the user if the Silverlight application can double the amount of available isolated storage.Asks the user if the Silverlight application can double the amount of available isolated storage.
6.Creating a file within a user's isolated storage areaCreating a file within a user's isolated storage area
7.Reading a file from a user's isolated storage area.Reading a file from a user's isolated storage area.
8.Using the * wildcard characterUsing the * wildcard character
9.Retrieving the isolated storage for a userRetrieving the isolated storage for a user