FileShare 列舉

定義

包含常數,用來控制其他 FileStream 物件對於相同檔案可以用的存取方式。Contains constants for controlling the kind of access other FileStream objects can have to the same file.

此列舉具有 FlagsAttribute 個屬性允許以位元方式合併其成員值。

public enum class FileShare
[System.Flags]
public enum FileShare
[System.Flags]
[System.Serializable]
public enum FileShare
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum FileShare
type FileShare = 
Public Enum FileShare
繼承
FileShare
屬性

欄位

Delete 4

允許後續刪除檔案。Allows subsequent deleting of a file.

Inheritable 16

使檔案控制代碼 (File Handle) 可由子處理序 (Process) 來繼承。Makes the file handle inheritable by child processes. 這並非直接由 Win32 來支援。This is not directly supported by Win32.

None 0

拒絕共用目前檔案。Declines sharing of the current file. 任何 (由這個處理序或其他處理序) 開啟檔案的要求將會失敗,直到關閉檔案。Any request to open the file (by this process or another process) will fail until the file is closed.

Read 1

允許後序開啟檔案進行讀取。Allows subsequent opening of the file for reading. 如果未指定這個旗標,任何 (由這個處理序或其他處理序) 開啟檔案進行讀取的要求將會失敗,直到關閉檔案。If this flag is not specified, any request to open the file for reading (by this process or another process) will fail until the file is closed. 然而,即使有指定這個旗標,可能仍然需要其他使用權限,才能存取檔案。However, even if this flag is specified, additional permissions might still be needed to access the file.

ReadWrite 3

允許後序開啟檔案進行讀取或寫入。Allows subsequent opening of the file for reading or writing. 如果未指定這個旗標,任何要開啟檔案以進行讀取或寫入的要求 (由這個處理序或其他處理序) 將會失敗,直到關閉檔案。If this flag is not specified, any request to open the file for reading or writing (by this process or another process) will fail until the file is closed. 然而,即使有指定這個旗標,可能仍然需要其他使用權限,才能存取檔案。However, even if this flag is specified, additional permissions might still be needed to access the file.

Write 2

允許後序開啟檔案進行寫入。Allows subsequent opening of the file for writing. 如果未指定這個旗標,任何 (由這個處理序或其他處理序) 開啟檔案進行寫入的要求將會失敗,直到關閉檔案。If this flag is not specified, any request to open the file for writing (by this process or another process) will fail until the file is closed. 然而,即使有指定這個旗標,可能仍然需要其他使用權限,才能存取檔案。However, even if this flag is specified, additional permissions might still be needed to access the file.

範例

下列 FileStream 的構造函式會開啟現有的檔案,並將唯讀存取權授與其他使用者(Read)。The following FileStream constructor opens an existing file and grants read-only access to other users (Read).

FileStream^ s2 = gcnew FileStream( name, FileMode::Open, FileAccess::Read, FileShare::Read );
FileStream s2 = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read);
Dim s2 As New FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read)

備註

如需建立檔案以及將文字寫入檔案的範例,請參閱如何:將文字寫入檔案。For an example of creating a file and writing text to a file, see How to: Write Text to a File. 如需從檔案讀取文字的範例,請參閱如何:從檔案讀取文字For an example of reading text from a file, see How to: Read Text from a File. 如需讀取和寫入二進位檔案的範例,請參閱如何:讀取和寫入新建立的資料檔案For an example of reading from and writing to a binary file, see How to: Read and Write to a Newly Created Data File.

此列舉的典型用法是定義兩個進程是否可以同時從相同的檔案讀取。A typical use of this enumeration is to define whether two processes can simultaneously read from the same file. 例如,如果檔案已開啟且指定了 Read,則其他使用者可以開啟檔案進行讀取,但不能寫入。For example, if a file is opened and Read is specified, other users can open the file for reading but not for writing.

在一些 FileFileInfoOpen 方法中,FileShare 參數指定于 FileStreamIsolatedStorageFileStream和的某些函式中,以控制檔案的開啟方式。A FileShare parameter is specified in some of the constructors for FileStream, IsolatedStorageFileStream, and in some of the Open methods of File and FileInfo to control how a file is opened.

適用於

另請參閱