title: Progressive streaming of video in asp.net
body: <p>I want to do progressive streaming of video in asp.net. I have written a code for that but still its not loading properly. Does any have idea about it.</p>
  
  <p>Please have look into my code or suggest me the best way to do it. I don't want player to wait for downloading whole video and then start playing. I want to start playing right now.</p>
  
  <p>Following is my code.</p>
  
  <pre><code>string path = "Test.mp4";
              string rootpath = Server.MapPath(Request.ApplicationPath);
              string file = string.Format(@"{0}\\{1}", rootpath, path);
              if (File.Exists(file) &amp;&amp; file.Contains("mp4"))
              {
                  FileStream filestream = new FileStream(file, FileMode.Open, FileAccess.Read);
                  long length = filestream.Length;
  
                  Response.AppendHeader("Content-Type", "video/mp4");
                  Response.AddHeader("Content-Disposition", "attachment; filename=" + path + "");
                  Response.AppendHeader("Content-Length", length.ToString());
  
                  const int buffersize = 16384;
                  byte[] buffer = new byte[buffersize];
  
                  int count = filestream.Read(buffer, 0, buffersize);
  
                  while (count &gt; 0)
                  {
                      if (!Response.IsClientConnected)
                          count = -1;
                      else
                      {
                          Response.OutputStream.Write(buffer, 0, count);
                          Response.Flush();
                          count = filestream.Read(buffer, 0, buffersize);
                      }
                  }
              }
  </code></pre>
  
  <p>Best Regards,
  Jalpesh</p>