Response.TransmitFile problem

Posted by geoff on Stack Overflow See other posts from Stack Overflow or by geoff
Published on 2009-12-03T03:13:30Z Indexed on 2010/03/18 18:31 UTC
Read the original article Hit count: 617

Filed under:
|
|

I have the following code delivering a file to users when they click on a download link. For security purposes I can't just link directly to the file so this was set up to decode the url and transmit the file. It has been working fine for a while but recently I started having problems where the file will start downloading but there's no indication of how large the file is. Because of this when the download should stop, it doesn't. The file is about 99mb but when I download it, the browser just keeps downloading way beyond 100mb. I don't know what it's downloading but if I don't cancel it, it doesn't stop. So, my question is, is there either an alternative to transmitfile or a way to make sure the size of the file is sent also so that it stops at the right time? I don't want to use writefile because I don't want to load the entire file into memory since it's so large. Thanks.

Here is the code:

string filename = Path.GetFileName(url); 
context.Response.Buffer = true; 
context.Response.Charset = ""; 
context.Response.Cache.SetCacheability(HttpCacheability.NoCache); 
context.Response.ContentType = "application/x-rar-compressed"; 
context.Response.AddHeader("content-disposition", "attachment;filename=" + filename);   
context.Response.TransmitFile(context.Server.MapPath(url)); context.Response.Flush(); 

© Stack Overflow or respective owner

Related posts about transmitfile

Related posts about file