Quote:
string path = fileuploadExcel.PostedFile.FileName;
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
Your code is running
on the server.
The
FileName
property returns the path - or sometimes just the name - of the file
on the client.
Code running on the server has
no access to the client's file system.
It might
appear to work when you're debugging your code in Visual Studio. But that's just because the server and the client are the same in that specific instance.
You need to save the posted file somewhere on the server, and then use the server path to read the file:
string excelPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString("N") + ".xls");
fileuploadExcel.SaveAs(excelPath);
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelPath + ";Extended Properties=Excel 12.0;Persist Security Info=False";
try
{
...
}
finally
{
System.IO.File.Delete(excelPath);
}