This documentation is archived and is not being maintained.

HttpResponse.WriteFile Method

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

Overload List

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

[Visual Basic] Overloads Public Sub WriteFile(String)
[C#] public void WriteFile(string);
[C++] public: void WriteFile(String*);
[JScript] public function WriteFile(String);

Writes the contents of the specified file into a memory block.

[Visual Basic] Overloads Public Sub WriteFile(String, Boolean)
[C#] public void WriteFile(string, bool);
[C++] public: void WriteFile(String*, bool);
[JScript] public function WriteFile(String, Boolean);

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

[Visual Basic] Overloads Public Sub WriteFile(IntPtr, Long, Long)
[C#] public void WriteFile(IntPtr, long, long);
[C++] public: void WriteFile(IntPtr, __int64, __int64);
[JScript] public function WriteFile(IntPtr, long, long);

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

[Visual Basic] Overloads Public Sub WriteFile(String, Long, Long)
[C#] public void WriteFile(string, long, long);
[C++] public: void WriteFile(String*, __int64, __int64);
[JScript] public function WriteFile(String, long, long);

Example

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.

[Visual Basic] 
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)
    

[C#] 
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);
    

[C++] 
String* FileName;
 FileInfo* MyFileInfo;
 __int64 StartPos = 0, FileSize;
 
 FileName = S"c:\\temp\\login.txt";
 MyFileInfo = new FileInfo(FileName);
 FileSize = MyFileInfo->Length;
 
 Response->Write(S"Please Login: <br>");
 Response->WriteFile(FileName, StartPos, FileSize);
    

[JScript] 
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)

See Also

HttpResponse Class | HttpResponse Members | System.Web Namespace

Show: