title: Best way to stream files in ASP.NET
body: <p>What's the best way to stream files using ASP.NET?</p>
  
  <p>There appear to be various methods for this, and I'm currently using the <a href="http://msdn.microsoft.com/en-us/library/12s31dhy(v=vs.110).aspx" rel="nofollow noreferrer">Response.TransmitFile()</a> method inside an http handler, which sends the file to the browser directly.  This is used for various things, including sending FLV's from outside the webroot to an embedded Flash video player.</p>
  
  <p>However, this doesn't seem like a reliable method.  In particular, there's a strange problem with <em>Internet Explorer (7)</em>, where the browser just hangs after a video or two are viewed.  Clicking on any links, etc have no effect, and the only way to get things working again on the site is to close down the browser and re-open it.</p>
  
  <p>This also occurs in other browsers, but much less frequently.  Based on some basic testing, I suspect this is something to do with the way files are being streamed... perhaps the connection isn't being closed properly, or something along those lines.</p>
  
  <p>After trying a few different things, I've found that the following method works for me:</p>
  
  <pre><code>Response.WriteFile(path);
  Response.Flush();
  Response.Close();
  Response.End();
  </code></pre>
  
  <p>This gets around the problem mentioned above, and viewing videos no longer causes Internet Explorer to hang.</p>
  
  <p>However, my understanding is that <a href="http://msdn.microsoft.com/en-us/library/system.web.httpresponse.writefile(v=vs.110).aspx" rel="nofollow noreferrer">Response.WriteFile()</a> loads the file into memory first, and given that some files being streamed could potentially be quite large, this doesn't seem like an ideal solution.</p>
  
  <p>I'm interested in hearing how other developers are streaming large files in ASP.NET, and in particular, streaming FLV video files.</p>