What does HttpResponse.WriteFile Method parameter bool readIntoMemory do?
The MSDN documentation is very unhelpful in this regard as I came across this method and wasn’t exactly sure why I’d want to do this or not do this.
Note: should anyone respond with “well it reads the file into memory” with no further explanation will be downvoted.
Looking with Reflector, it seems to indicate whether the file should be buffered in memory before being written to the response.
The file is opened using a
FileStreamand then if that boolean flag is set, it first reads the file into a byte array before writing that array to the response usingWriteBytes.If the flag is not set then the file is written to the response using
WriteFile.Both of the former scenarios make the assumption that a
HttpWriteris being used. If that’s not the case, thenWriteStreamAsTextis used.