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.

傳回

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.

適用於

另請參閱