title: Upload a file using file upload in ASP.net
body: <p>I wrote the  code to <strong>upload the file</strong> and <strong>save in project root directory</strong>. How can I change this to <strong>save the path into database</strong> and the <strong>files into a separate folder</strong> from project?</p>
  
  <pre><code>protected void UploadButton_Click(object sender, EventArgs e)
  {
      if(FileUploadControl.HasFile)
      {
          try
          {
              string filename = Path.GetFileName(FileUploadControl.FileName);
  
              FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
  
              StatusLabel.Text = "Upload status: File uploaded!";
          }
          catch(Exception ex)
          {
              StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
          }
      }
  }
  </code></pre>