Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

HttpResponse.WriteFile Method (String, Int64, Int64)

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

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

public void WriteFile (
	string filename,
	long offset,
	long size
)
public void WriteFile (
	String filename, 
	long offset, 
	long size
)
public function WriteFile (
	filename : String, 
	offset : long, 
	size : long
)
Not applicable.

Parameters

filename

The name 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.

Exception typeCondition

HttpException

offset is less than 0.

- or -

size is greater than the file size minus offset.

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

String fileName;
FileInfo myFileInfo;
long startPos = 0;
long fileSize;

fileName = "c:\\temp\\login.txt";
myFileInfo = new FileInfo(fileName);
fileSize = myFileInfo.get_Length();

get_Response().Write("Please Login: <br>");
get_Response().WriteFile(fileName, startPos, fileSize);

var fileName : String
var myFileInfo : FileInfo
var startPos : long = 0
var fileSize : long

fileName = "c:\\temp\\login.txt"
myFileInfo = new FileInfo(fileName)
fileSize = myFileInfo.Length 

Response.Write("Please Login: <br>")
Response.WriteFile(fileName, startPos, fileSize)


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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft