Export (0) Print
Expand All

HttpResponse.WriteFile Method (IntPtr, Int64, Int64)

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

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

'Declaration
Public Sub WriteFile ( _
	fileHandle As IntPtr, _
	offset As Long, _
	size As Long _
)
'Usage
Dim instance As HttpResponse
Dim fileHandle As IntPtr
Dim offset As Long
Dim size As Long

instance.WriteFile(fileHandle, offset, size)
public void WriteFile (
	IntPtr fileHandle, 
	long offset, 
	long size
)
public function WriteFile (
	fileHandle : IntPtr, 
	offset : long, 
	size : long
)

Parameters

fileHandle

The file handle of the file to write to the HTTP output stream.

offset

The byte position in the file where writing will start.

size

The number of bytes to write to the output stream.

When this method is used with large files, calling the method might result in 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" in the Microsoft Knowledge Base.

The following example writes the entire contents of a text file named "login.txt" (which might contain literal HTML text and input controls) directly to the output stream.

Dim MyFileStream As FileStream
 Dim FileName As String
 Dim FileHandle As IntPtr
 Dim StartPos As Long = 0, 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()
    

String fileName;
FileStream myFileStream;
IntPtr fileHandle;
long startPos = 0;
long fileSize;

fileName = "c:\\temp\\Login.txt";

myFileStream = new FileStream(fileName, FileMode.Open);
fileHandle = myFileStream.get_Handle();
fileSize = myFileStream.get_Length();

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

get_Response().WriteFile(fileHandle, startPos, fileSize);

myFileStream.Close();

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft