Freigeben über


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

  • Anonymous
    April 12, 2006
    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?
  • Anonymous
    April 12, 2006
    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.

    http://support.microsoft.com/?kbid=823409
    http://support.microsoft.com/?kbid=902780
  • Anonymous
    April 12, 2006
    thts an intresting feature.would defintely explore !
  • Anonymous
    April 12, 2006
    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.
  • Anonymous
    April 12, 2006
    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.
  • Anonymous
    April 13, 2006
    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.