title: Convert file received from jquery to byte array
body: <p>I need help in converting a file received from a jquery ajax to byte array. I'm using a  plugin called ajaxfileupload then from a jquery ajax call I send a file from a fileupload control to a handler. Here is my 
  handler code:</p>
  
  <pre><code>if (context.Request.Files.Count &gt; 0)
  {
      string path = context.Server.MapPath("~/Temp");
      if (!Directory.Exists(path))
          Directory.CreateDirectory(path);
  
      var file = context.Request.Files[0];
  
      string fileName;
  
      if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE")
      {
          string[] files = file.FileName.Split(new char[] { '\\' });
          fileName = files[files.Length - 1];
      }
      else
      {
          fileName = file.FileName;
      }
      string fileType = file.ContentType;
      string strFileName = fileName;
  
      FileStream fs = new FileStream("~/Temp/" + strFileName, FileMode.Open, FileAccess.Read);
      BinaryReader br = new BinaryReader(fs);
      Byte[] imagebytes = br.ReadBytes((Int32)fs.Length);
      br.Close();
      fs.Close();
  
      DBAccess dbacc = new DBAccess();
      dbacc.saveImage(imagebytes);
  
      string msg = "{";
      msg += string.Format("error:'{0}',\n", string.Empty);
      msg += string.Format("msg:'{0}'\n", strFileName);
      msg += "}";
      context.Response.Write(msg);
  }
  </code></pre>
  
  <p>I'm saving the file to a folder within a project then trying to retrieve that file and save it to the database. I can assure you that the image is being saved to the temp folder. The problem is with the line with (*) the file path is wrong. This is the file path that is being retrieved. "'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\~\Temp\2012-06-03 01.25.47.jpg'.". The temp folder is located locally inside my project and I want to retrieved the image within that folder. How can I set the file path to my desired location? Or is there another way to convert a file to byte array after retrieving it from a jquery ajax call?</p>
  
  <p>Credits to these articles:</p>
  
  <ul>
  <li><a href="http://www.aspsnippets.com/Articles/Save-and-Retrieve-Files-from-SQL-Server-Database-using-ASP.Net.aspx" rel="nofollow">Save and Retrieve Files from SQL Server Database using ASP.NET</a></li>
  <li><a href="http://weblogs.asp.net/jalpeshpvadgama/archive/2011/12/23/async-file-upload-with-jquery-and-asp-net.aspx" rel="nofollow">Async file upload with jQuery and ASP.NET</a></li>
  </ul>