Return to Snippet

Revision: 20586
at November 19, 2009 13:10 by pckujawa


Initial Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.IsolatedStorage;


//'.NET Framework Developer's Guide
//'Introduction to Isolated Storage
//'http://msdn.microsoft.com/en-us/library/3ak841sy.aspx

//'Isolation by User and Assembly. 
//'Isolation by User, Domain, and Assembly. 
//'http://msdn.microsoft.com/en-us/library/eh5d60e1.aspx

//'Where depends on Operating System
//'VISTA 
//'Roaming-enabled stores = <SYSTEMDRIVE>\Users\<user>\AppData\Roaming 
//'Nonroaming stores = <SYSTEMDRIVE>\Users\<user>\AppData\Local 
//'Pasted from <http://msdn.microsoft.com/en-us/library/3ak841sy.aspx> 



namespace HDI_WinForms_IsolatedStorage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void ButtonCreateFile_Click(object sender, EventArgs e)
        {
            IsolatedStorageFile isolatedStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
            IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("TestStore.txt", FileMode.Append, FileAccess.Write, isolatedStore);

            using (StreamWriter writer = new StreamWriter(isoStream))
            {
                writer.WriteLine("The Data " + DateTime.Now.ToShortTimeString());
            }
        }

        private void ButtonReadIsoFile_Click(object sender, EventArgs e)
        {
            IsolatedStorageFile isolatedStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
            IsolatedStorageFileStream isolatedStream = new IsolatedStorageFileStream("TestStore.txt", FileMode.Open, isolatedStore);
            using (StreamReader reader = new StreamReader(isolatedStream))
            {
                this.RichTextBox1.Text = reader.ReadToEnd();
            }
        }

        private void ButtonSpaceAvailable_Click(object sender, EventArgs e)
        {
            IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain, null, null);
            ulong spaceAvailable = isolatedStorage.MaximumSize - isolatedStorage.CurrentSize;
            this.LabelSpaceAvailable.Text = spaceAvailable.ToString();

        }

        private void ButtonDeleteIsoFile_Click(object sender, EventArgs e)
        {
            IsolatedStorageFile isolatedStorage;
            isolatedStorage = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
            isolatedStorage.DeleteFile("TestStore.txt");
        }
    }
}

Initial URL
http://windowsclient.net/learn/video.aspx?v=90634

Initial Description
Code taken from the video in the URL.

Initial Title
Isolated Storage in .NET (Reading, Writing, and Deleting a File; Checking Available Space)

Initial Tags

                                

Initial Language
C#