IsolatedStorageFile IsolatedStorageFile IsolatedStorageFile IsolatedStorageFile Class

定義

表示含有檔案和目錄的隔離儲存區 (Isolated Storage)。Represents an isolated storage area containing files and directories.

public ref class IsolatedStorageFile sealed : System::IO::IsolatedStorage::IsolatedStorage, IDisposable
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class IsolatedStorageFile : System.IO.IsolatedStorage.IsolatedStorage, IDisposable
type IsolatedStorageFile = class
    inherit IsolatedStorage
    interface IDisposable
Public NotInheritable Class IsolatedStorageFile
Inherits IsolatedStorage
Implements IDisposable
繼承
IsolatedStorageFileIsolatedStorageFileIsolatedStorageFileIsolatedStorageFile
屬性
實作

範例

下列程式碼範例說明如何在隔離存放區中建立檔案和目錄。The following code example illustrates how to create files and directories in an isolated store. 首先,依使用者、 定義域和組件隔離的存放區會擷取並放置於isoStore變數。First, a store that is isolated by user, domain, and assembly is retrieved and placed in the isoStore variable. CreateDirectory接著會呼叫方法來建立目錄和兩個執行個體IsolatedStorageFileStream類別建立這些目錄中的檔案。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()
    {
        using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null))
        {
            isoStore.CreateDirectory("TopLevelDirectory");
            isoStore.CreateDirectory("TopLevelDirectory/SecondLevel");
            isoStore.CreateDirectory("AnotherTopLevelDirectory/InsideDirectory");
            Console.WriteLine("Created directories.");

            isoStore.CreateFile("InTheRoot.txt");
            Console.WriteLine("Created a new file in the root.");

            isoStore.CreateFile("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt");
            Console.WriteLine("Created a new file in the InsideDirectory.");
        }
    }
}
Imports System.IO
Imports System.IO.IsolatedStorage

Module Module1
    Sub Main()
        Using isoStore As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, Nothing, Nothing)

            isoStore.CreateDirectory("TopLevelDirectory")
            isoStore.CreateDirectory("TopLevelDirectory/SecondLevel")
            isoStore.CreateDirectory("AnotherTopLevelDirectory/InsideDirectory")
            Console.WriteLine("Created directories.")

            isoStore.CreateFile("InTheRoot.txt")
            Console.WriteLine("Created a new file in the root.")

            isoStore.CreateFile("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt")
            Console.WriteLine("Created a new file in the InsideDirectory.")
        End Using
    End Sub
End Module

備註

此物件會對應至特定的隔離儲存區範圍內,檔案會由IsolatedStorageFileStream物件存在。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. 隔離儲存區範圍設定為特定的組件,因為大部分其他 managed 程式碼將無法存取您的程式碼的資料 (高度信任的 managed 程式碼和系統管理工具可以從其他組件存取存放區)。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 程式碼可以存取任何隔離的存放區。Unmanaged code can access any isolated stores.

如需詳細資訊,請參閱 隔離儲存區For more information, see Isolated Storage.

此類型會實作IDisposable介面。This type implements the IDisposable interface. 當您完成使用型別時,您應該處置它直接或間接。When you have finished using the type, you should dispose of it either directly or indirectly. 若要直接處置型別,呼叫其Dispose方法中的try / catch區塊。To dispose of the type directly, call its Dispose method in a try/catch block. 若要處置它間接,使用的語言建構這類using(在 C# 中) 或Using(在 Visual Basic)。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 如需詳細資訊,請參閱 「 使用物件,實作 IDisposable 」 一節IDisposable介面 > 主題。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

重要

Windows 8.x 市集Windows 8.x Store 應用程式無法使用隔離儲存區。Isolated storage is not available for Windows 8.x 市集Windows 8.x Store apps. 請改用 Windows.Storage 應用程式開發介面內含的 Windows 執行階段Windows Runtime 命名空間中的應用程式資料類別來儲存本機資料和檔案。Instead, use the application data classes in the Windows.Storage namespaces included in the Windows 執行階段Windows Runtime API to store local data and files. 如需詳細資訊,請參閱 Windows 開發人員中心的 應用程式資料For more information, see Application data in the Windows Dev Center.

屬性

AvailableFreeSpace AvailableFreeSpace AvailableFreeSpace AvailableFreeSpace

取得值,這個值表示隔離儲存區的可用空間量。Gets a value that represents the amount of free space available for isolated storage.

CurrentSize CurrentSize CurrentSize CurrentSize

取得隔離儲存區目前的大小。Gets the current size of the isolated storage.

IsEnabled IsEnabled IsEnabled IsEnabled

取得值,這個值表示隔離儲存區是否啟用。Gets a value that indicates whether isolated storage is enabled.

MaximumSize MaximumSize MaximumSize MaximumSize

取得值,表示隔離儲存區在配額建立起來的限制內可以使用的最大空間量。Gets a value representing the maximum amount of space available for isolated storage within the limits established by the quota.

Quota Quota Quota Quota

取得值,這個值表示隔離儲存區的最大可用空間量。Gets a value that represents the maximum amount of space available for isolated storage.

UsedSize UsedSize UsedSize UsedSize

取得值,這個值表示隔離儲存區的已使用空間量。Gets a value that represents the amount of the space used for isolated storage.

方法

Close() Close() Close() Close()

關閉先前由 GetStore(IsolatedStorageScope, Type, Type)GetUserStoreForAssembly()GetUserStoreForDomain() 開啟的存放區。Closes a store previously opened with GetStore(IsolatedStorageScope, Type, Type), GetUserStoreForAssembly(), or GetUserStoreForDomain().

CopyFile(String, String) CopyFile(String, String) CopyFile(String, String) CopyFile(String, String)

複製現有的檔案到新的檔案。Copies an existing file to a new file.

CopyFile(String, String, Boolean) CopyFile(String, String, Boolean) CopyFile(String, String, Boolean) CopyFile(String, String, Boolean)

複製現有的檔案到新檔案,並選擇性地覆寫現有的檔案。Copies an existing file to a new file, and optionally overwrites an existing file.

CreateDirectory(String) CreateDirectory(String) CreateDirectory(String) CreateDirectory(String)

在隔離儲存區範圍內建立目錄。Creates a directory in the isolated storage scope.

CreateFile(String) CreateFile(String) CreateFile(String) CreateFile(String)

在隔離儲存區中建立檔案。Creates a file in the isolated store.

DeleteDirectory(String) DeleteDirectory(String) DeleteDirectory(String) DeleteDirectory(String)

刪除隔離儲存區範圍內的目錄。Deletes a directory in the isolated storage scope.

DeleteFile(String) DeleteFile(String) DeleteFile(String) DeleteFile(String)

刪除隔離儲存區範圍內的檔案。Deletes a file in the isolated storage scope.

DirectoryExists(String) DirectoryExists(String) DirectoryExists(String) DirectoryExists(String)

判斷指定路徑是否參考隔離儲存區中的現有目錄。Determines whether the specified path refers to an existing directory in the isolated store.

Dispose() Dispose() Dispose() Dispose()

釋放 IsolatedStorageFile 所使用的所有資源。Releases all resources used by the IsolatedStorageFile.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
FileExists(String) FileExists(String) FileExists(String) FileExists(String)

判斷指定路徑是否參考隔離儲存區中的現有檔案。Determines whether the specified path refers to an existing file in the isolated store.

Finalize() Finalize() Finalize() Finalize()

允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

GetCreationTime(String) GetCreationTime(String) GetCreationTime(String) GetCreationTime(String)

傳回指定之檔案或目錄的建立日期和時間。Returns the creation date and time of a specified file or directory.

GetDirectoryNames() GetDirectoryNames() GetDirectoryNames() GetDirectoryNames()

列舉位於隔離儲存區根目錄的目錄。Enumerates the directories at the root of an isolated store.

GetDirectoryNames(String) GetDirectoryNames(String) GetDirectoryNames(String) GetDirectoryNames(String)

列舉隔離儲存區範圍中符合指定之搜尋模式的目錄。Enumerates the directories in an isolated storage scope that match a given search pattern.

GetEnumerator(IsolatedStorageScope) GetEnumerator(IsolatedStorageScope) GetEnumerator(IsolatedStorageScope) GetEnumerator(IsolatedStorageScope)

取得隔離儲存區範圍中 IsolatedStorageFile 存放區的列舉程式。Gets the enumerator for the IsolatedStorageFile stores within an isolated storage scope.

GetFileNames() GetFileNames() GetFileNames() GetFileNames()

列舉位於隔離儲存區根目錄的檔名。Enumerates the file names at the root of an isolated store.

GetFileNames(String) GetFileNames(String) GetFileNames(String) GetFileNames(String)

取得符合搜尋模式的檔名。Gets the file names that match a search pattern.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLastAccessTime(String) GetLastAccessTime(String) GetLastAccessTime(String) GetLastAccessTime(String)

傳回指定之檔案或目錄上次被存取的日期和時間。Returns the date and time a specified file or directory was last accessed.

GetLastWriteTime(String) GetLastWriteTime(String) GetLastWriteTime(String) GetLastWriteTime(String)

傳回指定之檔案或目錄上次被寫入的日期和時間。Returns the date and time a specified file or directory was last written to.

GetMachineStoreForApplication() GetMachineStoreForApplication() GetMachineStoreForApplication() GetMachineStoreForApplication()

取得對應於呼叫程式碼的應用程式識別之機器範圍隔離儲存區。Obtains machine-scoped isolated storage corresponding to the calling code's application identity.

GetMachineStoreForAssembly() GetMachineStoreForAssembly() GetMachineStoreForAssembly() GetMachineStoreForAssembly()

取得對應於呼叫程式碼的組件識別之機器範圍隔離儲存區。Obtains machine-scoped isolated storage corresponding to the calling code's assembly identity.

GetMachineStoreForDomain() GetMachineStoreForDomain() GetMachineStoreForDomain() GetMachineStoreForDomain()

取得對應於應用程式定義域識別和組件識別的機器範圍隔離儲存區。Obtains machine-scoped isolated storage corresponding to the application domain identity and the assembly identity.

GetStore(IsolatedStorageScope, Evidence, Type, Evidence, Type) GetStore(IsolatedStorageScope, Evidence, Type, Evidence, Type) GetStore(IsolatedStorageScope, Evidence, Type, Evidence, Type) GetStore(IsolatedStorageScope, Evidence, Type, Evidence, Type)

取得對應於指定應用程式定義域、組件辨識項物件和類型的隔離儲存區。Obtains isolated storage corresponding to the given application domain and the assembly evidence objects and types.

GetStore(IsolatedStorageScope, Object) GetStore(IsolatedStorageScope, Object) GetStore(IsolatedStorageScope, Object) GetStore(IsolatedStorageScope, Object)

取得對應於指定的應用程式識別之隔離儲存區。Obtains isolated storage corresponding to the given application identity.

GetStore(IsolatedStorageScope, Object, Object) GetStore(IsolatedStorageScope, Object, Object) GetStore(IsolatedStorageScope, Object, Object) GetStore(IsolatedStorageScope, Object, Object)

取得對應於指定應用程式定義域和組件辨識項物件的隔離儲存區。Obtains the isolated storage corresponding to the given application domain and assembly evidence objects.

GetStore(IsolatedStorageScope, Type) GetStore(IsolatedStorageScope, Type) GetStore(IsolatedStorageScope, Type) GetStore(IsolatedStorageScope, Type)

取得對應於隔離範圍和應用程式識別物件之隔離儲存區。Obtains isolated storage corresponding to the isolation scope and the application identity object.

GetStore(IsolatedStorageScope, Type, Type) GetStore(IsolatedStorageScope, Type, Type) GetStore(IsolatedStorageScope, Type, Type) GetStore(IsolatedStorageScope, Type, Type)

取得對應於指定應用程式定義域的隔離儲存區範圍和組件辨識項碼型的隔離儲存區。Obtains isolated storage corresponding to the isolated storage scope given the application domain and assembly evidence types.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
GetUserStoreForApplication() GetUserStoreForApplication() GetUserStoreForApplication() GetUserStoreForApplication()

取得對應於呼叫程式碼的應用程式識別之使用者範圍隔離儲存區。Obtains user-scoped isolated storage corresponding to the calling code's application identity.

GetUserStoreForAssembly() GetUserStoreForAssembly() GetUserStoreForAssembly() GetUserStoreForAssembly()

取得對應於呼叫程式碼的組件識別之使用者範圍隔離儲存區。Obtains user-scoped isolated storage corresponding to the calling code's assembly identity.

GetUserStoreForDomain() GetUserStoreForDomain() GetUserStoreForDomain() GetUserStoreForDomain()

取得對應於應用程式定義域識別和組件識別的使用者範圍隔離儲存區。Obtains user-scoped isolated storage corresponding to the application domain identity and assembly identity.

GetUserStoreForSite() GetUserStoreForSite() GetUserStoreForSite() GetUserStoreForSite()

取得使用者範圍隔離儲存區,以供虛擬主應用程式定義域中的應用程式使用。Obtains a user-scoped isolated store for use by applications in a virtual host domain.

IncreaseQuotaTo(Int64) IncreaseQuotaTo(Int64) IncreaseQuotaTo(Int64) IncreaseQuotaTo(Int64)

讓應用程式明確要求更大的配額大小 (以位元組為單位)。Enables an application to explicitly request a larger quota size, in bytes.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MoveDirectory(String, String) MoveDirectory(String, String) MoveDirectory(String, String) MoveDirectory(String, String)

移動指定的目錄和其內容到新位置。Moves a specified directory and its contents to a new location.

MoveFile(String, String) MoveFile(String, String) MoveFile(String, String) MoveFile(String, String)

移動指定的檔案至新的位置,並選擇性地讓您指定新檔名。Moves a specified file to a new location, and optionally lets you specify a new file name.

OpenFile(String, FileMode) OpenFile(String, FileMode) OpenFile(String, FileMode) OpenFile(String, FileMode)

使用指定模式來開啟檔案。Opens a file in the specified mode.

OpenFile(String, FileMode, FileAccess) OpenFile(String, FileMode, FileAccess) OpenFile(String, FileMode, FileAccess) OpenFile(String, FileMode, FileAccess)

使用指定的讀取/寫入存取,並以指定模式來開啟檔案。Opens a file in the specified mode with the specified read/write access.

OpenFile(String, FileMode, FileAccess, FileShare) OpenFile(String, FileMode, FileAccess, FileShare) OpenFile(String, FileMode, FileAccess, FileShare) OpenFile(String, FileMode, FileAccess, FileShare)

使用指定的讀取/寫入存取和共用使用權限,並以指定模式來開啟檔案。Opens a file in the specified mode, with the specified read/write access and sharing permission.

Remove() Remove() Remove() Remove()

移除隔離儲存區範圍和所有內容。Removes the isolated storage scope and all its contents.

Remove(IsolatedStorageScope) Remove(IsolatedStorageScope) Remove(IsolatedStorageScope) Remove(IsolatedStorageScope)

移除所有識別的指定隔離儲存區範圍。Removes the specified isolated storage scope for all identities.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

另請參閱