IsolatedStorageFile 類別

定義

代表包含檔案和目錄的隔離儲存區 (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
繼承
IsolatedStorageFile
屬性
實作

範例

下列程式碼範例說明如何在隔離存放區中建立檔案和目錄。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 方法來建立目錄,而 @no__t 1 類別的兩個實例會在這些目錄中建立檔案。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

備註

這個物件會對應至特定的隔離儲存範圍,其中 @no__t 0 的物件所代表的檔案存在。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 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. 若要直接處置型別,請呼叫其 try/catch 區塊中的 Dispose 方法。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

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

CurrentSize

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

IsEnabled

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

MaximumSize

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

Quota

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

UsedSize

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

方法

Close()

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

CopyFile(String, String)

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

CopyFile(String, String, Boolean)

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

CreateDirectory(String)

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

CreateFile(String)

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

DeleteDirectory(String)

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

DeleteFile(String)

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

DirectoryExists(String)

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

Dispose()

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

Equals(Object)

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

(繼承來源 Object)
FileExists(String)

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

Finalize()

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

GetCreationTime(String)

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

GetDirectoryNames()

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

GetDirectoryNames(String)

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

GetEnumerator(IsolatedStorageScope)

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

GetFileNames()

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

GetFileNames(String)

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

GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetLastAccessTime(String)

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

GetLastWriteTime(String)

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

GetMachineStoreForApplication()

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

GetMachineStoreForAssembly()

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

GetMachineStoreForDomain()

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

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)

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

GetStore(IsolatedStorageScope, Object, Object)

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

GetStore(IsolatedStorageScope, Type)

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

GetStore(IsolatedStorageScope, Type, Type)

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

GetType()

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

(繼承來源 Object)
GetUserStoreForApplication()

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

GetUserStoreForAssembly()

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

GetUserStoreForDomain()

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

GetUserStoreForSite()

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

IncreaseQuotaTo(Int64)

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

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MoveDirectory(String, String)

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

MoveFile(String, String)

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

OpenFile(String, FileMode)

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

OpenFile(String, FileMode, FileAccess)

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

OpenFile(String, FileMode, FileAccess, FileShare)

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

Remove()

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

Remove(IsolatedStorageScope)

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

ToString()

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

(繼承來源 Object)

適用於

另請參閱