HttpResponse.WriteFile HttpResponse.WriteFile HttpResponse.WriteFile HttpResponse.WriteFile Method

定义

将指定的文件直接写入 HTTP 响应输出流。Writes the specified file directly to an HTTP response output stream.

重载

WriteFile(IntPtr, Int64, Int64) WriteFile(IntPtr, Int64, Int64) WriteFile(IntPtr, Int64, Int64) WriteFile(IntPtr, Int64, Int64)

将指定的文件直接写入 HTTP 响应输出流。Writes the specified file directly to an HTTP response output stream.

WriteFile(String, Int64, Int64) WriteFile(String, Int64, Int64) WriteFile(String, Int64, Int64) WriteFile(String, Int64, Int64)

将指定的文件直接写入 HTTP 响应输出流。Writes the specified file directly to an HTTP response output stream.

WriteFile(String) WriteFile(String) WriteFile(String) WriteFile(String)

将指定文件的内容作为文件块直接写入 HTTP 响应输出流。Writes the contents of the specified file directly to an HTTP response output stream as a file block.

WriteFile(String, Boolean) WriteFile(String, Boolean) WriteFile(String, Boolean) 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) WriteFile(IntPtr, Int64, Int64) WriteFile(IntPtr, Int64, Int64) 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 IntPtr IntPtr IntPtr

要写入 HTTP 输出流的文件的文件句柄。The file handle of the file to write to the HTTP output stream.

offset
Int64 Int64 Int64 Int64

文件中将开始进行写入的字节位置。The byte position in the file where writing will start.

size
Int64 Int64 Int64 Int64

要写入输出流的字节数。The number of bytes to write to the output stream.

异常

offset 小于 0。offset is less than 0.

-or- size 大于文件大小与 offset 之差。size 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) WriteFile(String, Int64, Int64) WriteFile(String, Int64, Int64) 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 String String String

要写入 HTTP 输出流的文件名。The name of the file to write to the HTTP output stream.

offset
Int64 Int64 Int64 Int64

文件中将开始进行写入的字节位置。The byte position in the file where writing will start.

size
Int64 Int64 Int64 Int64

要写入输出流的字节数。The number of bytes to write to the output stream.

异常

offset 小于 0。offset is less than 0.

- 或 --or- size 大于文件大小与 offset 之差。size 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) WriteFile(String) WriteFile(String) 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 String String 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) WriteFile(String, Boolean) WriteFile(String, Boolean) 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 String String String

要写入内存块的文件名。The name of the file to write into a memory block.

readIntoMemory
Boolean Boolean Boolean 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.

适用于