title: how resume able file download in asp.net with c# -> best way (for large files too)
body: <p>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);
              //}
  
              if (HttpContext.Current.Session["User_ID"] != null)
              {
                  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 use this handler for downloading my files without opening them directly in browser -> (using query string path)  </p>
  
  <p>how can i make my files resumeable ?  </p>
  
  <p>i don't have that option in internet download manager!  </p>