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

Definition

Writes the specified file directly to an HTTP response output stream.

Overloads

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

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)

Writes the specified file directly to an HTTP response output stream.

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

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)

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)

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)
Parameters
fileHandle
IntPtr IntPtr IntPtr IntPtr

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.

Exceptions

offset is less than 0.

- or -

size is greater than the file size minus offset.

Examples

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()

Remarks

When this method is used with large files, calling the method might throw an exception. The size of the file that can be used with this method depends on the hardware configuration of the Web server. 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)

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)
Parameters
filename
String String String String

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.

Exceptions

offset is less than 0.

- or -

size is greater than the file size minus offset.

Examples

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)
    

Remarks

When this method is used with large files, calling the method might throw an exception. The size of the file that can be used with this method depends on the hardware configuration of the Web server. 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)

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)
Parameters
filename
String String String String

The name of the file to write to the HTTP output.

Exceptions

Examples

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")
    

Remarks

When this method is used with large files, calling the method might throw an exception. The size of the file that can be used with this method depends on the hardware configuration of the Web server. 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)

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)
Parameters
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.

Exceptions

Examples

The following example writes a file to memory.

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

Remarks

When this method is used with large files, calling the method might throw an exception. The size of the file that can be used with this method depends on the hardware configuration of the Web server. For more information, see article 812406, "PRB: Response.WriteFile Cannot Download a Large File" on the Microsoft Knowledge Base Web site.

Applies to