Microsoft Office Excel cannot accès the fichier 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Microsoft Office Excel cannot accès the fichier 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'

Message par ForumBot »

I have my code as follows :-

```
Microsoft.Office.Interop.Excel.Application oXL = null;
Microsoft.Office.Interop.Excel.Sheets sheets;
Application excel = new Microsoft.Office.Interop.Excel.Application();

excel.Workbooks.Add(System.Reflection.Missing.Value);

/*
* Here is the complete detail's about Workbook.Open()
*
* Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format,
* Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin,
* Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
*/

Workbook workbook = excel.Workbooks.Open(
System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Template.xlsx"),
Missing.Value, true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value);
sheets = workbook.Worksheets;

```

Now for the line :-

```
workbook = excel.Workbooks.Open(
System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Template.xlsx"),
Missing.Value, true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value);

```

It gets executed directly from the visual studio (F5) but when i try to access it with IIS it wont work.
Throws error as follows:-

>


Microsoft Office Excel cannot access the file 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'. 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.

I have tried the work around as:-

>


- Folder and the file exist, giving access to the IUSR_### (IIS user) and to the ASPNET user in the folder where the file is.




- At Component Services(DCOM) given access to appropriate user.



I have already given all permission's to the folder where the template(.xlsx) exists

Any suggestions??
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Microsoft Office Excel cannot accès the fichier 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'

Message par ForumBot »

Try this:

- Create the directory

>


C:\Windows\SysWOW64\config\systemprofile\Desktop

(for the 32-bit version of Excel/Office on a 64-bit Windows computer) or

>


C:\Windows\System32\config\systemprofile\Desktop

(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).

- For the *Desktop* directory, add *Full control* permissions for the
relevant user (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user *IIS AppPool\DefaultAppPool*).

Original post with answer:

- [Excel 2007 automation on top of a Windows Server 2008 x64](https://social.msdn.microsoft.com/Forums/en-US/b81a3c4e-62db-488b-af06-44421818ef91/excel-2007-automation-on-top-of-a-windows-server-2008-x64?forum=innovateonoffice)
Répondre

Revenir à « Excel & VBA »