Control.OpenFile(String) Control.OpenFile(String) Control.OpenFile(String) Control.OpenFile(String) Method

定义

获取用于读取文件的 StreamGets a Stream used to read a file.

protected public:
 System::IO::Stream ^ OpenFile(System::String ^ path);
protected internal System.IO.Stream OpenFile (string path);
member this.OpenFile : string -> System.IO.Stream
Protected Friend Function OpenFile (path As String) As Stream

参数

path
String String String String

所需文件的路径。The path to the desired file.

返回

引用所需文件的 StreamA Stream that references the desired file.

异常

对指定文件的访问被拒绝。Access to the specified file was denied.

注解

方法返回一个Stream对象,该对象可用于读取path参数中指定的文件的内容。 OpenFileThe OpenFile method returns a Stream object that can be used to read the contents of the file specified in the path parameter. Path 参数可以是不带协议的相对或根 URL (如 "~/mySite/myFile.txt"),也可以是物理路径(本地("c:\mySite\myFile.txt")或 UNC ("\\myServer\myFile.txt")。The path parameter can be either a relative or root URL without a protocol (such as "~/mySite/myFile.txt), or a physical path, either local ("c:\mySite\myFile.txt") or UNC ("\\myServer\myFile.txt").

OpenFile方法使用文件访问安全性来控制对指定文件的访问。The OpenFile method uses file access security to control access to the specified file. 如果当前 ASP.NET 用户无权访问该文件,则不会打开该文件,并HttpException引发异常以指示访问被拒绝。If the current ASP.NET user does not have access to the file, then the file is not opened and an HttpException exception is thrown to indicate that access was denied. path如果参数指定了相对路径,则异常不包含有关所请求文件的物理路径的信息。If the path parameter specified a relative path, the exception does not include information about the physical path to the requested file.

适用于

另请参阅