HttpResponse.WriteFile 方法

定義

將指定檔案直接寫入 HTTP 回應輸出資料流。Writes the specified file directly to an HTTP response output stream.

多載

WriteFile(IntPtr, Int64, Int64)

將指定檔案直接寫入 HTTP 回應輸出資料流。Writes the specified file directly to an HTTP response output stream.

WriteFile(String, Int64, Int64)

將指定檔案直接寫入 HTTP 回應輸出資料流。Writes the specified file directly to an HTTP response output stream.

WriteFile(String)

將指定的檔案內容直接寫入至 HTTP 回應輸出資料流,做為檔案區塊。Writes the contents of the specified file directly to an HTTP response output stream as a file block.

WriteFile(String, Boolean)

將指定的檔案內容直接寫入至 HTTP 回應輸出資料流,做為記憶體區塊。Writes the contents of the specified file directly to an HTTP response output stream as a memory block.

WriteFile(IntPtr, Int64, Int64)

將指定檔案直接寫入 HTTP 回應輸出資料流。Writes the specified file directly to an HTTP response output stream.

public:
 void WriteFile(IntPtr fileHandle, long offset, long size);
public void WriteFile (IntPtr fileHandle, long offset, long size);
member this.WriteFile : nativeint * int64 * int64 -> unit
Public Sub WriteFile (fileHandle As IntPtr, offset As Long, size As Long)

參數

fileHandle
IntPtr

要寫入 HTTP 輸出資料流之檔案的檔案控制代碼 (File Handle)。The file handle of the file to write to the HTTP output stream.

offset
Int64

檔案中開始寫入處的位元組位置。The byte position in the file where writing will start.

size
Int64

要寫入至輸出資料流的位元組數目。The number of bytes to write to the output stream.

例外狀況

fileHandlernullfileHandler is null.

offset 小於 0。offset is less than 0.

-或--or- size 大於檔案大小減去 offsetsize is greater than the file size minus offset.

範例

下列範例會將名為Login.txt的文字檔(可能包含常值 HTML 文字和輸入控制項)的所有內容直接寫入輸出資料流程。The following example writes all the contents of a text file named Login.txt (which might contain literal HTML text and input controls) directly to the output stream.

String FileName;
 FileStream MyFileStream;
 IntPtr FileHandle;
 long StartPos = 0, FileSize;
 
 FileName = "c:\\temp\\Login.txt";
 
 MyFileStream = new FileStream(FileName, FileMode.Open);
 FileHandle = MyFileStream.Handle;
 FileSize = MyFileStream.Length;
 
 Response.Write("<b>Login: </b>");
 Response.Write("<input type=text id=user /> ");
 Response.Write("<input type=submit value=Submit /><br><br>");
 
 Response.WriteFile(FileHandle, StartPos, FileSize);
    
 MyFileStream.Close();
    
Dim FileName As String
Dim MyFileStream As FileStream
Dim FileHandle As IntPtr
Dim StartPos As Long = 0
Dim FileSize As Long

FileName = "c:\\temp\\Login.txt"

MyFileStream = New FileStream(FileName, FileMode.Open)
FileHandle = MyFileStream.Handle
FileSize = MyFileStream.Length

Response.Write("<b>Login: </b>")
Response.Write("<input type=text id=user /> ")
Response.Write("<input type=submit value=Submit /><br><br>")

Response.WriteFile(FileHandle, StartPos, FileSize)
   
MyFileStream.Close()

備註

當此方法與大型檔案搭配使用時,呼叫方法可能會擲回例外狀況。When this method is used with large files, calling the method might throw an exception. 可以搭配此方法使用的檔案大小取決於 Web 服務器的硬體設定。The size of the file that can be used with this method depends on the hardware configuration of the Web server. 如需詳細資訊,請參閱文章 812406 < PRB:回應。 WriteFile 無法下載大型檔案」,請到Microsoft 知識庫網站。For more information, see article 812406, "PRB: Response.WriteFile Cannot Download a Large File" on the Microsoft Knowledge Base Web site.

WriteFile(String, Int64, Int64)

將指定檔案直接寫入 HTTP 回應輸出資料流。Writes the specified file directly to an HTTP response output stream.

public:
 void WriteFile(System::String ^ filename, long offset, long size);
public void WriteFile (string filename, long offset, long size);
member this.WriteFile : string * int64 * int64 -> unit
Public Sub WriteFile (filename As String, offset As Long, size As Long)

參數

filename
String

要寫入 HTTP 輸出資料流的檔案名稱。The name of the file to write to the HTTP output stream.

offset
Int64

檔案中開始寫入處的位元組位置。The byte position in the file where writing will start.

size
Int64

要寫入至輸出資料流的位元組數目。The number of bytes to write to the output stream.

例外狀況

offset 小於 0。offset is less than 0.

-或--or- size 大於檔案大小減去 offsetsize is greater than the file size minus offset.

filename 參數為 nullThe filename parameter is null.

範例

下列範例會將名為Login.txt的文字檔(可能包含常值文字和 HTML 輸入控制項)的所有內容直接寫入輸出資料流程。The following example writes all the contents of a text file named Login.txt (which might contain literal text and HTML input controls) directly to the output stream.

String FileName;
 FileInfo MyFileInfo;
 long StartPos = 0, FileSize;
 
 FileName = "c:\\temp\\login.txt";
 MyFileInfo = new FileInfo(FileName);
 FileSize = MyFileInfo.Length;
 
 Response.Write("Please Login: <br>");
 Response.WriteFile(FileName, StartPos, FileSize);
    
Dim FileName As String
 Dim MyFileInfo As FileInfo
 Dim StartPos, FileSize As Long
 
 FileName = "c:\\temp\\login.txt"
 MyFileInfo = New FileInfo(FileName)
 FileSize = MyFileInfo.Length 
 
 Response.Write("Please Login: <br>")
 Response.WriteFile(FileName, StartPos, FileSize)
    

備註

當此方法與大型檔案搭配使用時,呼叫方法可能會擲回例外狀況。When this method is used with large files, calling the method might throw an exception. 可以搭配此方法使用的檔案大小取決於 Web 服務器的硬體設定。The size of the file that can be used with this method depends on the hardware configuration of the Web server. 如需詳細資訊,請參閱文章 812406 < PRB:回應。 WriteFile 無法下載大型檔案」,請到Microsoft 知識庫網站。For more information, see article 812406, "PRB: Response.WriteFile Cannot Download a Large File" on the Microsoft Knowledge Base Web site.

WriteFile(String)

將指定的檔案內容直接寫入至 HTTP 回應輸出資料流,做為檔案區塊。Writes the contents of the specified file directly to an HTTP response output stream as a file block.

public:
 void WriteFile(System::String ^ filename);
public void WriteFile (string filename);
member this.WriteFile : string -> unit
Public Sub WriteFile (filename As String)

參數

filename
String

要寫入 HTTP 輸出的檔案名稱。The name of the file to write to the HTTP output.

例外狀況

filename 參數為 nullThe filename parameter is null.

範例

下列範例會將名為Login.txt的文字檔(可能包含常值 HTML 文字和輸入控制項)的所有內容直接寫入輸出資料流程。The following example writes all the contents of a text file named Login.txt (which might contain literal HTML text and input controls) directly to the output stream.

Response.Write("Please Login: <br>");
 Response.WriteFile("login.txt");
    
Response.Write("Please Login: <br>")
 Response.WriteFile("login.txt")
    

備註

當此方法與大型檔案搭配使用時,呼叫方法可能會擲回例外狀況。When this method is used with large files, calling the method might throw an exception. 可以搭配此方法使用的檔案大小取決於 Web 服務器的硬體設定。The size of the file that can be used with this method depends on the hardware configuration of the Web server. 如需詳細資訊,請參閱文章 812406 < PRB:回應。 WriteFile 無法下載大型檔案」,請到Microsoft 知識庫網站。For more information, see article 812406, "PRB: Response.WriteFile Cannot Download a Large File" on the Microsoft Knowledge Base Web site.

WriteFile(String, Boolean)

將指定的檔案內容直接寫入至 HTTP 回應輸出資料流,做為記憶體區塊。Writes the contents of the specified file directly to an HTTP response output stream as a memory block.

public:
 void WriteFile(System::String ^ filename, bool readIntoMemory);
public void WriteFile (string filename, bool readIntoMemory);
member this.WriteFile : string * bool -> unit
Public Sub WriteFile (filename As String, readIntoMemory As Boolean)

參數

filename
String

要寫入記憶體區塊的檔案名稱。The name of the file to write into a memory block.

readIntoMemory
Boolean

指示檔案將是否被寫入記憶體區塊。Indicates whether the file will be written into a memory block.

例外狀況

filename 參數為 nullThe filename parameter is null.

範例

下列範例會將檔案寫入記憶體。The following example writes a file to memory.

Response.WriteFile("login.txt", true);
    
Response.WriteFile("login.txt", True)
    

備註

當此方法與大型檔案搭配使用時,呼叫方法可能會擲回例外狀況。When this method is used with large files, calling the method might throw an exception. 可以搭配此方法使用的檔案大小取決於 Web 服務器的硬體設定。The size of the file that can be used with this method depends on the hardware configuration of the Web server. 如需詳細資訊,請參閱文章 812406 < PRB:回應。 WriteFile 無法下載大型檔案」,請到Microsoft 知識庫網站。For more information, see article 812406, "PRB: Response.WriteFile Cannot Download a Large File" on the Microsoft Knowledge Base Web site.

適用於