title: Save a jpg image to my webform and link it to my database?
body: <p>I have set up a webform for employees to input data, which is connected to a SQL test server with a database I created. I now want to upload an image (.jpg) from the users computer(dir) and save image to the server path (which is currently on my computer for now) into a folder I designated, and save the path to server/database. Also while saving, how can I include the filename with the employee id attached?</p>
  
  <p>Using visual studio 2015, I have already created a fileupload button and onclick button to save everything. When I run the program through the browser (firefox), it seems to run smoothly with no errors. The dignostics tool shows me ASP.NET: Save State completed"/WebF.</p>
  
  <p>After it runs, when I hover my mouse over some text, it shows some parts have worked, up until:</p>
  
  <pre><code>if (FileUpload1.HasFile)
  </code></pre>
  
  <p>I have checked on this site for different solutions but they don't seem to work. e.g <code>image.save();</code> and <code>image.saveAs();</code> which haven't worked. Maybe I'm doing it wrong and I don't understand C# yet.</p>
  
  <p>I used an example from Microsofts docs .net help pages but that doesn't seem to work completely.</p>
  
  <p>This is the code I got from Microsofts .net help pages.</p>
  
  <pre><code>protected void UploadButton_Click(object sender, EventArgs e)
  {
      string saveDir = @"~\Visual Studio 2015\Projects\EMPMIS\PASSPORTS";
  
      string MainPath = Request.PhysicalApplicationPath;
  
      string EMPLOYEEID = TXTEMPID.Text;
      string UserFile = FileUpload1.FileName;
  
      if (FileUpload1.HasFile)
      {
          string savePath = MainPath + EMPLOYEEID + Server.HtmlEncode(UserFile);
  
          // Append the name of the file to upload to the path.
          //string EMPLOYEEID = TXTEMPID.Text;
          // savePath += fileName + EMPLOYEEID;
  
          FileUpload1.SaveAs(savePath);
  
          UploadStatusLabel.Text = "Your file was saved as " + UserFile;
      }
      else
      {
          UploadStatusLabel.Text = "You did not specify a file to upload.";
      }
  }
  </code></pre>
  
  <p><strong>EDIT</strong>
  The solution was to change to the saveDir path to an absolute path rather than a relative path, which solved my issue.</p>
  
  <p>string saveDir = @"C:...\Visual Studio 2015\Projects\EMPMIS\PASSPORTS";</p>