title: File uploaded WITHOUT its content to web service using jquery ajax
body: <p>I am uploading file using jquery ajax but the problem is file is uploaded without its content. FIle uploaded with 0Kb. Here is my code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  function uploading() {
  var u = document.getElementById('uploadbr');
  alert(u.value);
  
                      $.ajax({ 
                          type: "POST",
                          url: "http://10.20.1.93:8080/Service1/UploadFile?fileName="+u.value, 
  
                          success: function( data ) 
                          { 
                              alert( data ); 
                          } 
                      });    
                  } 
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form name="uploadform" encrypt="multipart/form-data"&gt;
  &lt;input id="uploadbr" type="file" name="upfile" size="40" /&gt;&lt;br/&gt;
  &lt;input type="button" name="upbutton" value="Upload" onclick="uploading()" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my code on server side.</p>
  
  <pre><code> [WebInvoke(Method = "POST", UriTemplate = "UploadFile?fileName={fileName}")]
          public string UploadFile(string fileName, Stream fileContents)
          {
              //save file
              try
              {
                  string absFileName = string.Format("{0}\\FileUpload\\{1}"
                                          , AppDomain.CurrentDomain.BaseDirectory
                                          , fileName);
                  using (FileStream fs = new FileStream(absFileName, FileMode.Create))
                  {
                      fileContents.CopyTo(fs);
                      fileContents.Close();
                  }
                  return "Upload OK";
              }
              catch (Exception ex)
              {
                  return "FAIL ==&gt; " + ex.Message;
              }
          }
  </code></pre>
  
  <p>Now tell me what can i do? where am i wrong? </p>