Click here to Skip to main content
15,891,841 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have a small project in VS2015 asp.net - c#, to read excel file data's. When I run it as localhost it's working fine. But after hosting to FTP, it's not working, giving error like
"
The Microsoft Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data.

My Connection String - XLSX file

//String MyExcelFile = Server.MapPath(MyInput1.PostedFile.FileName); // Not Working
//String MyExcelFile = System.IO.Path.GetFullPath(Server.MapPath(MyInput1.PostedFile.FileName)); // Not Working

String MyExcelFile = MyInput1.PostedFile.FileName; // Working good in localhost
But giving error after published to ftp...........??????

String StrConn2 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + MyExcelFile + "; Extended Properties=\"Excel 12.0; HDR=YES; \"";

String MyExcelSheet = "[Sheet1$]";
String  MySQLSelect = "select * from " + MyExcelSheet;

Thanks for the helps !

What I have tried:

Read Excel File Data using Microsoft.Ace.Oledb.12.0
Posted
Updated 21-Aug-17 6:49am

One usually uses a client side application to fill a webform with data from local Excel, or other local applications. Or writes to a server Excel file for download. Microsoft makes it difficult to work with Excel via automation, even local.
 
Share this answer
 
You can use ClosedXML as alternative, which is more reliable than Microsoft.ACE.OLEDB.

Project URL: https://github.com/ClosedXML/ClosedXML[^]
 
Share this answer
 
This seems to be a good library: EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx). EPPlus-Create advanced Excel spreadsheets on the server - Home[^]
 
Share this answer
 
Quote:
//String MyExcelFile = Server.MapPath(MyInput1.PostedFile.FileName); // Not Working
//String MyExcelFile = System.IO.Path.GetFullPath(Server.MapPath(MyInput1.PostedFile.FileName)); // Not Working
String MyExcelFile = MyInput1.PostedFile.FileName; // Working good in localhost

The FileName property returns the path - or sometimes just the name - of the file on the client.

Your code is running on the server. It does not have access to the client's file system.

It appears to work when you're debugging in Visual Studio. But that's only because, in that specific case, the client and server happen to be the same.

You have two options:
  1. Use MyInput1.SaveAs(...) to save the file somewhere on the server, and then read the server's copy. You will need to use a random filename, since multiple users might be accessing your site at the same time, and you don't want the file from one user to overwrite the file from a different user.
  2. Use a library which lets you read the file from a Stream, without saving it to disk. You can then pass in MyInput1.FileContent, which gives you access to the raw content of the uploaded file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900