Question

I have created a C# service that:

- Picks up and opens a local text file
- Opens an Excel-file used as template (saved locally)
- Fills in the data from the text file in the excel file
- Saves the Excel file to a network folder.

The service runs using a domain account (I cannot give the local system account rights on the network from our network admin...). When the service tries to open the template, I get an access denied error:

Microsoft Excel cannot access the file 'C:\BloxVacation\Template\BloxTemplate.xlsm'. 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 file does exist and the path is correct. The file is not used by another user or program. I try to OPEN the workbook (no other workbook is open), not SAVE it.

I have received the same error using the system account. The reason for this is that, when using interopservices, the system account needs a desktop folder (bug in Windows 7: http://forums.asp.net/t/1585488.aspx).

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

Create those 2 files and the error disappears for the system account.

I have given the domain user rights to those folders and the error disappears as well however, the service hangs on the code line where I open the excel file. When I execute the exact same code with the system account, the code execute well (Note: I save the file locally).

 objXL.Workbooks.Open(BloxVacationService.ExcelTemplateFilePath)

Has anybody an idea how to solve this issue without having to rewrite the entire service in OpenXML? Thank you very much in advance.

Was it helpful?

Solution

If you have done all the things described in the question and it still doesn't work (as it was with me), the answer is pretty simple:

Make the domain user local admin on the machine that runs the service. It solved the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top