I have an MVC web application that allows user to upload an Excel files to Azure cloud storage, and then the application uses that Azure-stored Excel blob file to import data into SQL Server.
I follow the sites http://www.codeproject.com/Tips/752981/Import-Data-from-Excel-File-to-Database-Table-in-A
and
Upload Excel File and Extract Data from it and put that data in database using MVC asp.net
to do my application. However, the example from the site http://www.codeproject.com/Tips/752981/Import-Data-from-Excel-File-to-Database-Table-in-A lets users upload file to web server where application is deployed not Azure storage, and the contents of "fileLocation" variable (please see the below codes) looks like (relative to web-server-hosted application path C or whatever drive) "C:\MyWebApplicationFolder\MyApplicatioName\Content\Excel_blob.xlsx"
My question: for Azure storage Excel blob files, how can I specify the value of "fileLocation" and "excelConnectionString" variables? Please see my code comments starting with phrase "// *** How can I can do this with Azure storage codes?" below.
Codes from http://www.codeproject.com/Tips/752981/Import-Data-from-Excel-File-to-Database-Table-in-A
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
DataSet ds = new DataSet();
if (Request.Files["file"].ContentLength > 0)
{
string fileExtension = System.IO.Path.GetExtension(Request.Files["file"].FileName);
if (fileExtension == ".xls" || fileExtension == ".xlsx")
{
string fileLocation = Server.MapPath("~/Content/") + Request.Files["file"].FileName; // *** How can I can do this with Azure storage codes?
if (System.IO.File.Exists(fileLocation))
{
System.IO.File.Delete(fileLocation);
}
Request.Files["file"].SaveAs(fileLocation);
string excelConnectionString = string.Empty;
excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; // *** How can I can do this with Azure storage codes?
//connection String for xls file format.
if (fileExtension == ".xls")
{
excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; // *** How can I can do this with Azure storage codes?
}
//connection String for xlsx file format.
else if (fileExtension == ".xlsx")
{
excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; // *** How can I can do this with Azure storage codes?
}
...