SYSK 103: WriteFile or TransmitFile?

Both, HttpResponse.WriteFile and HttpResponse.TransmitFile (new in 2.0) write the contents of a file to the output stream.  However, WriteFile will load the whole file into the memory while TransmitFile won’t.  So, if you’ve been using WriteFile, you may want to give TransmitFile a consideration…


Comments (6)

  1. Peter Ritchie says:

    Does TransmitFile lock the file so no other processes can write to it until the tramsmission is done, too?  Or, is the programmer responsible for ensuring the file does not change while TransmitFile is executing?

  2. Per says:

    TransmitFile exists in .NET 1.1 SP1 also, but it doesnt work in Win2003 SP1 ofcourse which is the normal deployment environment. You have to request a hotfix from MS.

  3. srinivas says:

    thts an intresting feature.would defintely explore !

  4. Also TransmitFile avoids kernel/user mode transitions which reduces (significantly) the amount of overhead per call.  It’s just a shame that it was exposed in .NET so poorly compared to the native Win32 TransmitFile.

  5. irenake says:

    Excellent question!  I couldn’t find the answer in the docs, but my tests show that that TransmitFile does not lock the file while executing.

  6. Peter Ritchie says:

    Thanks for the follow-up; I would have eventually tested it out myself before using TransmitFile; but, don’t have the time right now.

    Much appreciated.