title: direct file download instead of opening with a handler - file size showing issue
body: <p>plz see the below handler :  </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace FileExplorer
  {
      /// &lt;summary&gt;
      /// Summary description for HandlerForMyFE
      /// &lt;/summary&gt;
      public class HandlerForMyFE : IHttpHandler, System.Web.SessionState.IRequiresSessionState
      {
  
          private HttpContext _context;
          private HttpContext Context
          {
              get
              {
                  return _context;
              }
              set
              {
                  _context = value;
              }
          }
  
          public void ProcessRequest(HttpContext context)
          {
              Context = context;
              string filePath = context.Request.QueryString["Downloadpath"];
              filePath = context.Server.MapPath(filePath);
  
              if (filePath == null)
              {
                  return;
              }
  
              System.IO.StreamReader streamReader = new System.IO.StreamReader(filePath);
              System.IO.BinaryReader br = new System.IO.BinaryReader(streamReader.BaseStream);
  
              byte[] bytes = new byte[streamReader.BaseStream.Length];
  
              br.Read(bytes, 0, (int)streamReader.BaseStream.Length);
  
              if (bytes == null)
              {
                  return;
              }
  
              streamReader.Close();
              br.Close();
              string fileName = System.IO.Path.GetFileName(filePath);
              string MimeType = GetMimeType(fileName);
              string extension = System.IO.Path.GetExtension(filePath);
              char[] extension_ar = extension.ToCharArray();
              string extension_Without_dot = string.Empty;
              for (int i = 1; i &lt; extension_ar.Length; i++)
              {
                  extension_Without_dot += extension_ar[i];
              }
  
              //if (extension == ".jpg")
              //{ // Handle *.jpg and
              //    WriteFile(bytes, fileName, "image/jpeg jpeg jpg jpe", context.Response);
              //}
              //else if (extension == ".gif")
              //{// Handle *.gif
              //    WriteFile(bytes, fileName, "image/gif gif", context.Response);
              //}
  
              WriteFile(bytes, fileName, MimeType + " " + extension_Without_dot, context.Response);
          }
  
          private void WriteFile(byte[] content, string fileName, string contentType, HttpResponse response)
          {
              response.Buffer = true;
              response.Clear();
              response.ContentType = contentType;
  
              response.AddHeader("content-disposition", "attachment; filename=" + fileName);
  
              response.BinaryWrite(content);
              response.Flush();
              response.End();
          }
  
          private string GetMimeType(string fileName)
          {
              string mimeType = "application/unknown";
              string ext = System.IO.Path.GetExtension(fileName).ToLower();
              Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
              if (regKey != null &amp;&amp; regKey.GetValue("Content Type") != null)
                  mimeType = regKey.GetValue("Content Type").ToString();
              return mimeType;
          }
  
          public bool IsReusable
          {
              get
              {
                  return false;
              }
          }
      }
  }
  </code></pre>
  
  <p>i wrote that handler for direct download file after clicking without opening that file in browser...<br>
  it seems the upper codes work!<br>
  but there is a problem for showing file size during download.<br>
  for test that plz see the below link :<br>
  <a href="http://www.asanfile.com/Default.aspx?path=/Samsung/Video%20Training" rel="nofollow">Test with internet download manager</a><br>
  in that link we do n't have file size, but in the link below we have it :<br>
  <a href="http://www.asanfile.com/Default.aspx?path=/Samsung" rel="nofollow">another link</a><br>
  what is the problem of my handler and how can i fix this issue?  </p>
  
  <p>thanks in advance</p>