Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am using an IIS application to launch a windows service which then opens a (2003 or 2007) Excel file. When my Excel add-in receive the 'open' message, it will try use the following code to open the Excel file.
Microsoft.Office.Interop.Excel.Application.Workbooks.Open(fName, False, 1) 'fName is the path to the file

Then I got the exception:
"Microsoft Office Excel cannot access the file 'C:\...\Book2003.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 file is not in use and the path is correct. And I have given everyone full permission on that file. I am using windows 7 64-bit, Excel 2007 sp2 and IIS 7. The folder "C:\Windows\SysWOW64\config\systemprofile\Desktop" does exist.
Could anybody help please?

Thanks
Posted

Hi Chas,

Forgive me, but your solution seems a bit strange. You use a IIS application to launch a windows service? Windows service are intended to run continously in the background. A better architecture for you application would be to have the windows service continuously running in the background, have the iis application connect to the windows service using a webservice call (the webservice would be hosted in the windows service).

Regarding you question, there could be a lot of thing wrong. For example under which user account is the windows service running? Does this account have enough rights to open the excel file? Also normally windows services are not allowed to show an user interface. It is a option on a windows service "to allow interaction with the desktop"

You could use a tool like process monitor to check under which account the file is being opened.

Hope this helps.
 
Share this answer
 
Comments
Chasxu 2-Mar-11 5:28am    
Thanks Patrick for your reply.

Sorry I did not make it right. The windows service is always running under my user account, which should have all the permissions.


The process monitor found something wrong with the Excel process:
Operation: CreateFileMapping
Result: FILE LOCKED WITH ONLY READERS
Path: C:\...\book.xlsx

Operation: RegOpenKey
Result: ACCESS DENIED
Path: HKCU\Software\Microsoft\Office\12.0\Common\Open Find

I checked the file is not read only and I got all the permissions on it and in the registry.

:(
Mark Ward 21-Mar-11 16:08pm    
Chas,

I'm trying to do EXACTLY the same thing, and (not surprisingly) I'm getting EXACTLY the SAME ERROR.

For anyone wishing to comment, MY app can run EITHER as an application OR as a Service.

When run as an APPLICATION - it works FINE (and there's NO GUI) - Excel opens the file "silently".

When running as a SERVICE (under the SAME DOMAIN ACCOUNT/PASSWORD) - the OPEN fails!

NOTE: WORD works FINE (no errors).

I'm fairly sure it has SOMETHING to do with Excel THINKING it IS running "interactively" (with a GUI), where WORD is SMARTER (hard to believe, I know).

Bottom line, it's NOT the File Permissions, it's NOT the Account under which Excel is being instantiated - it's SOMETHING Excel is doing (that, frankly, it SHOULD NOT BE DOING)!

Chas,
If I discover a work-around, I'll post it.

Regards,
Mark Ward
Carson, CA
Mark Ward 21-Mar-11 16:43pm    
SOLVED!

It appears that "SIMPLY" by creating a "Desktop" directory in:
(for an x64 based Operating System)
%WINDIR%\SysWow64\Config\SystemProfile

(for x86 based Operating System)
%WINDIR%\System32\Config\SystemProfile

THAT'S IT!

Voila - Excel can NOW open files!
Member 11595621 1-Jun-15 6:41am    
Hi mark,

I am facing a similar issue. I am using Windows Server 2012(64 bit). My excel file generation path is in D Drive.I have created the desktop folders in the given path but still not working :( .. Please guide us.
Raúl Martos 6-May-14 3:18am    
Thanks Mark! Your "Simply" solution worked!
Thanks Mark! I was facing the same issue on an upgrade to Windows Server 2019. Added the Desktop folder to C:\Windows\SysWow64\Config\SystemProfile. Problem SOVLED!!!
 
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