Welcome to MSDN Blogs Sign in | Join | Help

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…

 

Published Wednesday, April 12, 2006 7:01 AM by irenak

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: SYSK 103: WriteFile or TransmitFile?

Wednesday, April 12, 2006 10:24 AM by Peter Ritchie
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?

# re: SYSK 103: WriteFile or TransmitFile?

Wednesday, April 12, 2006 10:49 AM by Per
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

# re: SYSK 103: WriteFile or TransmitFile?

Wednesday, April 12, 2006 12:23 PM by srinivas
thts an intresting feature.would defintely explore !

# re: SYSK 103: WriteFile or TransmitFile?

Wednesday, April 12, 2006 1:24 PM by RobertHorvick
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.

# SYSK 103: Reply to Peter Ritchie

Wednesday, April 12, 2006 8:41 PM by irenak
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.

# Reply to Irena, RE locking

Thursday, April 13, 2006 10:31 AM by Peter Ritchie
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.

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker