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.

備註

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

適用於

另請參閱