title: System.IO.FileNotFoundExecption, GUID are different for filename stored in database and file stored on server
body: <p>I am trying to use GUID to allow users to upload files with same names, but the GUIDs attach to filenames &amp; filepaths stored in database are different from the GUIDs attached to the files stored on server. It means it is giving two different GUIDs to the same file. So when I am trying to download the file from server its giving me an FileNotFound exception as the command arguement takes the filename from database and therefore when it goes to server its not able to find the file as the GUID of the same file stored on the server is different.
  Please if anybody can give me some advise that would be appreciable.</p>
  
  <p>My Database schema:</p>
  
  <pre><code>Table: Sales
  Columns: ReceiptFileName(Stores Name without GUID)
  Coulmn:ReceiptFilePath(Stores file path with GUID)
  Column: filename(Stores filename with GUID)
  </code></pre>
  
  <p>Aspx code:</p>
  
  <pre><code>&lt;ItemTemplate&gt;
       &lt;asp:LinkButton ID="LinkButton1" runat="server" CommandName="Download" CommandArgument='&lt;%# Bind("filename") %&gt;' Text='&lt;%# Bind("ReceiptFileName") %&gt;' &gt;&lt;/asp:LinkButton&gt;
  &lt;/ItemTemplate&gt;
  </code></pre>
  
  <p>Code for upload:</p>
  
  <pre><code>if (FileUpload1.HasFile)
  {
      //check file Extension &amp; Size
      string filename = FileUpload1.PostedFile.FileName;
  
      {
          filename = filename + Guid.NewGuid();
      }
  
      int filesize = FileUpload1.PostedFile.ContentLength;
  
      if (filesize &gt; (20 * 1024))
      {
          Label1.Text = "Please upload a zip or a pdf file";
      }
  
      string fileextention = System.IO.Path.GetExtension(FileUpload1.FileName);
  
      if (fileextention.ToLower() != ".zip" &amp;&amp; fileextention.ToLower() != ".pdf")
      {
          Label1.ForeColor = System.Drawing.Color.Green;
          Label1.Text = "Please upload a zip or a pdf file";
      }
      else
      {
          //string ReceiptFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
          string ReceiptFileName = Path.GetFileName(filename);
  
          //save file to disk
          FileUpload1.SaveAs(Server.MapPath("~/Reimbursement/Reciepts/" + ReceiptFileName));
      }
  }
  </code></pre>
  
  <p>Method for adding filename and receiptname</p>
  
  <pre><code>public static int AddSale(SaleID,  string ReceiptFileName,string ReceiptFilePath, string filename)
  {
      int sale;
      SqlCommand addSales = new SqlCommand("addSale", con);
  
      addSale.CommandType = CommandType.StoredProcedure;
      addSale.Parameters.AddWithValue("@ReceiptFileName", ReceiptFileName);
      addSale.Parameters.AddWithValue("@filename", filename);
      addSale.Parameters.AddWithValue("@ReceiptFilePath", ReceiptFilePath);
  
      try
      {
          con.Open();
          added = addSale.ExecuteNonQuery();
      }
  
      finally
      {
          con.Close();
      }
  </code></pre>
  
  <p>Code for download:</p>
  
  <pre><code>protected void gridExpenditures_RowCommand(object sender, GridViewCommandEventArgs e)
  {
      if (e.CommandName == "Download")
      {
          Response.Clear();
          Response.ContentType = "application/octet-stream";
          Response.AppendHeader("content-disposition", "FileName=" + e.CommandArgument);
          Response.TransmitFile(Server.MapPath("~/Reimbursement/Reciepts/") + e.CommandArgument);
          Response.End();
      }
  }
  </code></pre>