Friday, January 26, 2007

System.IO.IsolatedStorage represents an isolated storage area containing files and directories

StorageHelper Class

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

namespace Utility
{
  public static class StorageHelper
  {

    /// <summary>
    /// Saves the content to the file.
    /// </summary>s
    public static void Save(string fileName, string content)
    {
      using (IsolatedStorageFile isoStore =
            IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
      {
        using (StreamWriter writer = new StreamWriter(
                new IsolatedStorageFileStream(fileName, FileMode.Create, isoStore)))
        {
          writer.Write(content);
        }
      }
    }

    /// <summary>
    /// Loads the content of the file.
    /// </summary>
    public static string Load(string fileName)
    {
      using (IsolatedStorageFile isoStore =
            IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
      {
        if (isoStore.GetFileNames(fileName).Length > 0)
        {
          using (StreamReader reader = new StreamReader(
                new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, isoStore)))
          {
            return reader.ReadToEnd();
          }
        }
      }

      return null;
    }

    /// <summary>
    /// Deletes the file to clear the settings.
    /// </summary>
    public static void Delete(string fileName)
    {
      using (IsolatedStorageFile isoStore =
            IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
      {
        if (isoStore.GetFileNames(fileName).Length > 0)
          isoStore.DeleteFile(fileName);
      }
    }

  }
}

Storeadm Command Line
Microsoft (R) .NET Framework Store Admin 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.

Usage : StoreAdm [options]
options : [/LIST] [/REMOVE] [/ROAMING | /MACHINE] [/QUIET]
/LIST : Displays the existing isolated storage for the current user.
/REMOVE : Removes all existing isolated storage for the current user.
/ROAMING : Select the roaming store.
/QUIET : Only error messages will be output.
/MACHINE : Select the machine store.

References

http://blog.joycode.com/musicland/archive/2004/03/10/15629.aspx
http://msdn2.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.aspx

0 comments: