title: File upload with c# and streaming
body: <p>Looking at the different ways to upload a file in .NET, e.g. HttpPostedFile, and using a HttpHandler, I'm trying to understand how the process works in a bit more details.</p>
  <p>Specifically how it writes the information to a file.</p>
  <p>Say I have the following:</p>
  <pre><code>HttpPostedFile file = context.Request.Files[0];
  file.SaveAs(&quot;c:\temp\file.zip&quot;);
  </code></pre>
  <p>The actual file does not get created until the full stream seems to be processed.</p>
  <p>Similarly:</p>
  <pre><code>using (Stream output = File.OpenWrite(&quot;c:\temp\file.zip&quot;))
  using (Stream input = file.InputStream)
  {
      byte[] buffer = new byte[8192];
      int bytesRead;
      while ((bytesRead = input.Read(buffer, 0, buffer.Length)) &gt; 0)
      {
          output.Write(buffer, 0, bytesRead);
      }
  }
  </code></pre>
  <p>I would have thought that this would &quot;progressively&quot; write the file as it reads the stream. Looking at the filesystem, it does not seems to do this at all. If I breakpoint inside the while, it does though.</p>
  <p>What I'm trying to do, is have it so you upload a file (using a javascript uploader), and poll alongside, whereby the polling ajax request tries to get the fileinfo(file size) of the uploaded file every second. However, it always returns 0 until the upload is complete.</p>
  <p>Vimeo seems to be able to do this type of functionality (for IE)?? Is this a .NET limitation, or is there a way to progressively write the file from the stream?</p>