title: ASP: Copying a file path in full into my code-behind method
body: <p>I want to copy an excel file to my database. The problem I'm having is I cant seem to copy the path from  into the code-behind. This is my asp code:</p>
  
  <pre><code>    &lt;asp:FileUpload id="FileUploadControl" runat="server" /&gt;
      &lt;asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" /&gt;
      &lt;br /&gt;&lt;br /&gt;
      &lt;asp:Label runat="server" id="StatusLabel" text="Upload status: " /&gt;
  </code></pre>
  
  <p>if I hard code in a path then my code will work:</p>
  
  <pre><code>string path = @"C:\Users\moynik\Desktop\datatest.xls";
  </code></pre>
  
  <p>but if I use the following line I only get a different path that will not work. </p>
  
  <pre><code>string path = Path.GetFullPath(FileUploadControl.FileName);
  </code></pre>
  
  <p>but I need to make my path dynamic so users can upload from different destinations on there own computer. Can anyone help me out. this is the function which works and copys the excel file to my database</p>
  
  <p>If this is impossible can someone help me with a solution if they think of one. Thanks</p>
  
  <pre><code>protected void UploadButton_Click(object sender, EventArgs e)
  {
      if (FileUploadControl.HasFile)
      {
          try
          {
              string path = @"C:\Users\moynik\Desktop\datatest.xls";
              string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=Excel 8.0;";
  
  
  
      using (OleDbConnection connection = new OleDbConnection(connStr))
              {
                  OleDbCommand command = new OleDbCommand ("Select Name,Address,Age FROM [Sheet1$]", connection);
  
                  connection.Open();
  
                  using (DbDataReader dr = command.ExecuteReader())
                  { 
                      string sqlConnectionString = "SERVER=&lt;servername&gt;;UID=schafc;Trusted_Connection=Yes;DATABASE=&lt;dbname&gt;;";
  
                      using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
                      {
                          bulkCopy.DestinationTableName = "&lt;tableName&gt;";
                          bulkCopy.WriteToServer(dr);
                      }
                  }
              } 
              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>