Control.OpenFile(String) 方法

定義

取得用來讀取檔案的 Stream

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

所需要之檔案的路徑。

傳回

Stream

Stream,參考所需要的檔案。

例外狀況

存取指定的檔案遭拒絕。

備註

方法會 OpenFileStream 回 物件,可用來讀取 參數中指定的 path 檔案內容。 path 參數可以是沒有通訊協定 (的相對或根 URL,例如 「~/mySite/myFile.txt) ,或是實體路徑,可以是本機 (」c:\mySite\myFile.txt「) 」) 或 UNC (「 \\myServer\myFile.txt」) 」。

方法 OpenFile 會使用檔案存取安全性來控制對指定檔案的存取。 如果目前的 ASP.NET 使用者沒有檔案的存取權,則不會開啟檔案,而且 HttpException 會擲回例外狀況,指出存取遭到拒絕。 path如果參數指定相對路徑,則例外狀況不包含所要求檔案實體路徑的相關資訊。

適用於

另請參閱