Reputation: 2807
I have the following problem: I have a client who will upload an Excel file online. This Excel file will need to be imported to a database table, which I can do using the openrowset
command. Once it has been imported, I can display the data using a GridView
.
Now, I have referred http://www.codeproject.com/KB/books/ASPNET20FileUpload.aspx and http://msdn.microsoft.com/en-us/library/aa478971.aspx, but in both of them, the upload folder (destination) is hardcoded. How can I change this to reflect the file's destination to be on the server? And, once this is done, how can I then use openrowset
to extract the contents of the Excel fie?
Additionally, how can I emulate the entire process on my machine before it is deployed?
Upvotes: 1
Views: 482
Reputation: 52241
You can store your file on server like..
FileUpload1.SaveAs(Server.MapPath("~/temp/xyz.xlsx"));
and then set that in connection string like..
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/temp/xyz.xlsx"); Extended Properties=Excel 12.0;";
Upvotes: 2