In an ASP.NET MVC app, I am trying to read data from Excel file but I get this error:
Microsoft Excel cannot access the file 'C:\Users\PC\Desktop\qqq\Content\Uploads\dataFile.xls'.
There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
The error appears in production mode, but in development mode there's no problem.
I am making host on Local Host on my computer
I created a simple example and reproduced your problem. Please check if the following directories exist:
For a 32-bit version of Office on a 32-bit Windows computer or a 64-bit version of Office on a 64-bit Windows computer:
C:\Windows\System32\config\systemprofile\Desktop
For the 32-bit version of Excel/Office on a 64-bit Windows computer:
C:\Windows\SysWOW64\config\systemprofile\Desktop
In most cases (my test too), you should be able to solve this problem by creating the first directory, unless your environment is somewhat special, you can try creating a second directory to see if it works for you. For more details, you could refer to this similar case: Microsoft Office Excel cannot access the file 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'