title: Download a file using ajax from ASP.Net Webforms
body: <p>I need to download a file that is created on the server as a binary array, as follows:</p>
  
  <p>Server code is handler page (ashx):</p>
  
  <pre><code>public void ProcessRequest(HttpContext context)
      {
          var cId = context.Request.QueryString["CanID"];
  
          if (int.Parse(cId ) &gt; 0)
          {
              var sc = ControllerAccess.Instance();
              var cv = sc.GetUser(int.Parse(cId), SessionHandler.LoggedOnUser);
              if (cv.Bytes != null &amp;&amp; cv.Bytes.Length &gt; 0)
              {
                  var dTime = DateTime.Now.ToString("yyyyMMddhhmmss");
  
                  var response = HttpContext.Current.Response;
                  response.ClearContent();
                  response.Clear();
                  response.ContentType = "text/plain";
                  response.AddHeader("Content-Disposition", "attachment;filename=" + dTime + "-" + Id + "-" + "CandidateRecord" + cv.FileExtension);
                  response.BinaryWrite(cv.Bytes);
                  response.Flush();
                  response.End();
              }
          }
      }
  </code></pre>
  
  <p>How Can I get that file on the client using ajax? Any ideas?</p>