Control.OpenFile(String) 方法


取得用來讀取檔案的 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



所需要之檔案的路徑。The path to the desired file.


Stream,參考所需要的檔案。A Stream that references the desired file.


存取指定的檔案遭拒絕。Access to the specified file was denied.


OpenFile 方法會傳回 Stream 物件,可用來讀取 path 參數中指定之檔案的內容。The 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.