2 out of 4 rated this helpful - Rate this topic

IsolatedStorageFile Class

Updated: October 2010

Represents an isolated storage area containing files and directories.

System.Object
  System.MarshalByRefObject
    System.IO.IsolatedStorage.IsolatedStorage
      System.IO.IsolatedStorage.IsolatedStorageFile

Namespace:  System.IO.IsolatedStorage
Assembly:  mscorlib (in mscorlib.dll)
[ComVisibleAttribute(true)]
public sealed class IsolatedStorageFile : IsolatedStorage, 
	IDisposable

The IsolatedStorageFile type exposes the following members.

  Name Description
Public property ApplicationIdentity Gets an application identity that scopes isolated storage. (Inherited from IsolatedStorage.)
Public property AssemblyIdentity Gets an assembly identity used to scope isolated storage. (Inherited from IsolatedStorage.)
Public property AvailableFreeSpace Gets a value that represents the amount of free space available for isolated storage. (Overrides IsolatedStorage.AvailableFreeSpace.)
Public property CurrentSize Obsolete. Gets the current size of the isolated storage. (Overrides IsolatedStorage.CurrentSize.)
Public property DomainIdentity Gets a domain identity that scopes isolated storage. (Inherited from IsolatedStorage.)
Public property Static member IsEnabled Gets a value that indicates whether isolated storage is enabled.
Public property MaximumSize Obsolete. Gets a value representing the maximum amount of space available for isolated storage within the limits established by the quota. (Overrides IsolatedStorage.MaximumSize.)
Public property Quota Gets a value that represents the maximum amount of space available for isolated storage. (Overrides IsolatedStorage.Quota.)
Public property Scope Gets an IsolatedStorageScope enumeration value specifying the scope used to isolate the store. (Inherited from IsolatedStorage.)
Protected property SeparatorExternal Gets a backslash character that can be used in a directory string. When overridden in a derived class, another character might be returned. (Inherited from IsolatedStorage.)
Protected property SeparatorInternal Gets a period character that can be used in a directory string. When overridden in a derived class, another character might be returned. (Inherited from IsolatedStorage.)
Public property UsedSize Gets a value that represents the amount of the space used for isolated storage. (Overrides IsolatedStorage.UsedSize.)
Top
  Name Description
Public method Close Closes a store previously opened with GetStore, GetUserStoreForAssembly, or GetUserStoreForDomain.
Public method CopyFile(String, String) Copies an existing file to a new file.
Public method CopyFile(String, String, Boolean) Copies an existing file to a new file, and optionally overwrites an existing file.
Public method CreateDirectory Creates a directory in the isolated storage scope.
Public method CreateFile Creates a file in the isolated store.
Public method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method DeleteDirectory Deletes a directory in the isolated storage scope.
Public method DeleteFile Deletes a file in the isolated storage scope.
Public method DirectoryExists Determines whether the specified path refers to an existing directory in the isolated store.
Public method Dispose Releases all resources used by the IsolatedStorageFile.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public method FileExists Determines whether the specified path refers to an existing file in the isolated store.
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetCreationTime Returns the creation date and time of a specified file or directory.
Public method GetDirectoryNames() Enumerates the directories at the root of an isolated store.
Public method GetDirectoryNames(String) Enumerates the directories in an isolated storage scope that match a given search pattern.
Public method Static member GetEnumerator Gets the enumerator for the IsolatedStorageFile stores within an isolated storage scope.
Public method GetFileNames() Enumerates the file names at the root of an isolated store.
Public method GetFileNames(String) Gets the file names that match a search pattern.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLastAccessTime Returns the date and time a specified file or directory was last accessed.
Public method GetLastWriteTime Returns the date and time a specified file or directory was last written to.
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method Static member GetMachineStoreForApplication Obtains machine-scoped isolated storage corresponding to the calling code's application identity.
Public method Static member GetMachineStoreForAssembly Obtains machine-scoped isolated storage corresponding to the calling code's assembly identity.
Public method Static member GetMachineStoreForDomain Obtains machine-scoped isolated storage corresponding to the application domain identity and the assembly identity.
Protected method GetPermission When implemented by a derived class, returns a permission that represents access to isolated storage from within a permission set. (Inherited from IsolatedStorage.)
Public method Static member GetStore(IsolatedStorageScope, Object) Obtains isolated storage corresponding to the given application identity.
Public method Static member GetStore(IsolatedStorageScope, Type) Obtains isolated storage corresponding to the isolation scope and the application identity object.
Public method Static member GetStore(IsolatedStorageScope, Object, Object) Obtains the isolated storage corresponding to the given application domain and assembly evidence objects.
Public method Static member GetStore(IsolatedStorageScope, Type, Type) Obtains isolated storage corresponding to the isolated storage scope given the application domain and assembly evidence types.
Public method Static member GetStore(IsolatedStorageScope, Evidence, Type, Evidence, Type) Obtains isolated storage corresponding to the given application domain and the assembly evidence objects and types.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Static member GetUserStoreForApplication Obtains user-scoped isolated storage corresponding to the calling code's application identity.
Public method Static member GetUserStoreForAssembly Obtains user-scoped isolated storage corresponding to the calling code's assembly identity.
Public method Static member GetUserStoreForDomain Obtains user-scoped isolated storage corresponding to the application domain identity and assembly identity.
Public method Static member GetUserStoreForSite Infrastructure. Obtains a user-scoped isolated store for use by applications in a virtual host domain.
Public method IncreaseQuotaTo Enables an application to explicitly request a larger quota size, in bytes. (Overrides IsolatedStorage.IncreaseQuotaTo(Int64).)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method InitStore(IsolatedStorageScope, Type) Initializes a new IsolatedStorage object. (Inherited from IsolatedStorage.)
Protected method InitStore(IsolatedStorageScope, Type, Type) Initializes a new IsolatedStorage object. (Inherited from IsolatedStorage.)
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public method MoveDirectory Moves a specified directory and its contents to a new location.
Public method MoveFile Moves a specified file to a new location, and optionally lets you specify a new file name.
Public method OpenFile(String, FileMode) Opens a file in the specified mode.
Public method OpenFile(String, FileMode, FileAccess) Opens a file in the specified mode with the specified read/write access.
Public method OpenFile(String, FileMode, FileAccess, FileShare) Opens a file in the specified mode, with the specified read/write access and sharing permission.
Public method Remove() Removes the isolated storage scope and all its contents. (Overrides IsolatedStorage.Remove().)
Public method Static member Remove(IsolatedStorageScope) Removes the specified isolated storage scope for all identities.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top

This object corresponds to a specific isolated storage scope, where files represented by IsolatedStorageFileStream objects exist. Applications can use isolated storage to save data in their own isolated portion of the file system, without having to specify a particular path within the file system. Since isolated stores are scoped to particular assemblies, most other managed code will not be able to access your code's data (highly trusted managed code and administration tools can access stores from other assemblies). Unmanaged code can access any isolated stores.

For more information, see Isolated Storage.

The following code example illustrates how to create files and directories in an isolated store. First, a store that is isolated by user, domain, and assembly is retrieved and placed in the isoStore variable. The CreateDirectory method is then called to create directories, and two instances of the IsolatedStorageFileStream class create files in these directories.


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

public class CreatingFilesDirectories
{
    public static void Main()
    {
        // Get a new isolated store for this user, domain, and assembly.
        // Put the store into an IsolatedStorageFile object.

        IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
            IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);

        // This code creates a few different directories.

        isoStore.CreateDirectory("TopLevelDirectory");
        isoStore.CreateDirectory("TopLevelDirectory/SecondLevel");

        // This code creates two new directories, one inside the other.
        isoStore.CreateDirectory("AnotherTopLevelDirectory/InsideDirectory");

        // This file is placed in the root.

        IsolatedStorageFileStream isoStream1 =
            new IsolatedStorageFileStream("InTheRoot.txt", FileMode.Create, isoStore);
        Console.WriteLine("Created a new file in the root.");
        isoStream1.Close();

        // This file is placed in the InsideDirectory.

        IsolatedStorageFileStream isoStream2 =
            new IsolatedStorageFileStream("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt",
            FileMode.Create, isoStore);
        isoStream2.Close();

        Console.WriteLine("Created a new file in the InsideDirectory.");
    } // End of Main.
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Date

History

Reason

October 2010

Added example.

Customer feedback.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
IsolatedStorageTest
/// <see cref="http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.aspx"/>
/// <see cref="http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile.aspx"/>
/// <see cref="http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefilestream.aspx"/>
[TestMethod]
public void StorageTest()
{
    string storageFolder = "Exam70536";
    string storageFile = @"Exam70536\exam.txt";

    // IsolatedStorage (abstract)

    //var storeApp = IsolatedStorageFile.GetUserStoreForApplication(); ??
    var storeAss = IsolatedStorageFile.GetUserStoreForAssembly(); // User\App Data
    var storeDom = IsolatedStorageFile.GetUserStoreForDomain();
    //var storeSit = IsolatedStorageFile.GetUserStoreForSite(); ??

    //var storeAppM = IsolatedStorageFile.GetMachineStoreForApplication(); ??
    var storeAssM = IsolatedStorageFile.GetMachineStoreForAssembly(); // ProgramData
    var storeDomM = IsolatedStorageFile.GetMachineStoreForDomain();

    if (!storeAss.DirectoryExists(storageFolder))
        storeAss.CreateDirectory(storageFolder); // override folder
    Assert.IsTrue(storeAss.DirectoryExists(storageFolder));

    if (!storeAss.FileExists(storageFile))
        storeAss.CreateFile(storageFile);
    Assert.IsTrue(storeAss.FileExists(storageFile));

    storeDom.CreateDirectory(storageFolder);
    Assert.IsTrue(storeDom.DirectoryExists(storageFolder));
    //storeSit.CreateDirectory(storageFolder);

    //storeAppM.CreateDirectory(storageFolder);
    storeAssM.CreateDirectory(storageFolder);
    Assert.IsTrue(storeAssM.DirectoryExists(storageFolder));
    storeDomM.CreateDirectory(storageFolder);
    Assert.IsTrue(storeDomM.DirectoryExists(storageFolder));

    Process.Start(System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile));
}