Hello all...
I need to read the data from an excel file in my ASP.NET 2.0 application. I am using the following C# code:
The code works, but I have three issues:
1 - I get the error "The Microsoft Jet database engine cannot open the file '[some path]\myExcelFile.xls'. It is already opened exclusively by another user, or you need permission to view its data." The reason for the error is obvious: The ASP.NET user does not have permission to the folder. Now, in my development machine, the solution to this is pretty simple - adjust the folder permissions appropriately. However, what about the end user who is using my asp.net app to upload excel files? His excel file could be located anywhere in his machine and the aspnet user may not have access to it. How do I get around this without having the user (a) change the permissions on his folders, or (b) put the excel file in a specific location?
2 - What about that Sheet1$, huh? What if the user has changed the name of the sheet where the data is? How do I access that?
3 - Multiple Excel versions? What if the user has a version of excel different than "Excel 8.0" ?
Thanks.
_________________________________
I think, therefore I am. [Rene Descartes]
I need to read the data from an excel file in my ASP.NET 2.0 application. I am using the following C# code:
Code:
OleDbConnection cn = new OleDbConnection();
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + [i]inputFile.PostedFile.FileName[/i] + ";" +
"Extended Properties=Excel 8.0;";
OleDbDataAdapter cmd = new OleDbDataAdapter("SELECT * FROM [b][Sheet1$][/b]", cn);
...
The code works, but I have three issues:
1 - I get the error "The Microsoft Jet database engine cannot open the file '[some path]\myExcelFile.xls'. It is already opened exclusively by another user, or you need permission to view its data." The reason for the error is obvious: The ASP.NET user does not have permission to the folder. Now, in my development machine, the solution to this is pretty simple - adjust the folder permissions appropriately. However, what about the end user who is using my asp.net app to upload excel files? His excel file could be located anywhere in his machine and the aspnet user may not have access to it. How do I get around this without having the user (a) change the permissions on his folders, or (b) put the excel file in a specific location?
2 - What about that Sheet1$, huh? What if the user has changed the name of the sheet where the data is? How do I access that?
3 - Multiple Excel versions? What if the user has a version of excel different than "Excel 8.0" ?
Thanks.
_________________________________
I think, therefore I am. [Rene Descartes]