title: upload file using jquery and handler(ashx)
body: <p>I am trying to upload a file using jquery ajax with handler (c#). The problem is, when I call the handler I get </p>
  
  <pre><code>context.Request.File.Count=0
  </code></pre>
  
  <p>Here is the aspx code:</p>
  
  <pre><code>&lt;!--aspx file code--&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  $().ready(function () 
  {
      $('#save').click(function (e)
      {
          CalluploaderHandler();
      });
  });
  
  function CalluploaderHandler()
  {
      $.ajax({
                  type: "POST",
                  url: "Services/UPloader.ashx",
                  contentType: "application/json; charset=utf-8",
                  success: OnComplete,
                  error: OnFail
              });
      return false;
  }
  
  function OnComplete(result)
  {
      alert('Success');
  }
  
  function OnFail(result)
  {
      alert('Request failed');
  }
  
  &lt;/script&gt;
      &lt;/head&gt;
          &lt;body&gt;
              &lt;form  enctype="multipart/form-data"&gt;
                  &lt;label for="file"&gt;
                  Filename:&lt;/label&gt;
                  &lt;input name="file" id="file" type="file"&gt;
                  &lt;input id="save" name="submit" value="Submit" type="submit"&gt;
              &lt;/form&gt;
          &lt;/body&gt;
      &lt;/html&gt;    
  </code></pre>
  
  <p>The c# code handler:</p>
  
  <pre><code>/* handler*/
  public void ProcessRequest(HttpContext context)
  {
      string savedFileName = "";
  
      foreach (string file in context.Request.Files)
      {
          HttpPostedFile hpf = context.Request.Files[file] as HttpPostedFile;
          if (hpf.ContentLength == 0)
              continue;
          // savedFileName = context.Server.MapPath(Path.GetFileName(hpf.FileName));
          // hpf.SaveAs(savedFileName);
      }
      context.Response.Write(savedFileName);
  }
  </code></pre>