FileShare FileShare FileShare FileShare Enum

定义

包含用于控制其他 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]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum FileShare
type FileShare = 
Public Enum FileShare
继承
属性

字段

Delete Delete Delete Delete 4

允许随后删除文件。Allows subsequent deleting of a file.

Inheritable Inheritable Inheritable Inheritable 16

使文件句柄可由子进程继承。Makes the file handle inheritable by child processes. Win32 不直接支持此功能。This is not directly supported by Win32.

None None None 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 Read Read 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 ReadWrite ReadWrite 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 Write Write 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构造函数打开一个现有文件,并向其他用户 (读取) 授予只读访问权限。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. 例如,如果打开文件时,指定读取其他用户可以打开文件进行读取,但不是进行写入。For example, if a file is opened and Read is specified, other users can open the file for reading but not for writing.

一个Read参数指定的构造函数的一些FileStreamIsolatedStorageFileStream,和中的一些Open方法FileFileInfo来控制如何打开文件。A Read 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.

适用于

另请参阅