The difference is the time when the file's contents are read.
If you pass true
for readIntoMemory
, the file stream is opened, read into memory and closed, and all of that happens during WriteFile
. On the other hand, if you pass false
, the file stream is opened and closed again without reading (just to verify that the file exists). Instead, the information about which file to write is passed into some internal buffer (using the internal HttpWriter.WriteFile
method). Later (probably when the response is flushed, but I haven't verified this), the file's contents will be read.
Consider the following code:
protected void Page_Load(object sender, EventArgs e)
{
Response.WriteFile(@"C:\myFile", false);
System.IO.File.Move(@"C:\myFile", "C:\myFile2");
Response.End();
}
Note that your browser won't receive a response, i.e., something goes terribly bad during Response.End
. Setting readIntoMemory
to true
avoids this problem.