HttpResponse.WriteFile Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Writes the specified file directly to an HTTP response output stream.
Overloads
WriteFile(IntPtr, Int64, Int64) |
Writes the specified file directly to an HTTP response output stream. |
WriteFile(String, Int64, Int64) |
Writes the specified file directly to an HTTP response output stream. |
WriteFile(String) |
Writes the contents of the specified file directly to an HTTP response output stream as a file block. |
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)
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
nativeint
The file handle of the file to write to the HTTP output stream.
- offset
- Int64
The byte position in the file where writing will start.
- size
- Int64
The number of bytes to write to the output stream.
Exceptions
fileHandler
is null
.
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.
Applies to
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
The name of the file to write to the HTTP output stream.
- offset
- Int64
The byte position in the file where writing will start.
- size
- Int64
The number of bytes to write to the output stream.
Exceptions
The filename
parameter is null
.
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.
Applies to
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
The name of the file to write to the HTTP output.
Exceptions
The filename
parameter is null
.
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.
Applies to
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
The name of the file to write into a memory block.
- readIntoMemory
- Boolean
Indicates whether the file will be written into a memory block.
Exceptions
The filename
parameter is null
.
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.