Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
2.23/5 (4 votes)
See more:
Hi,

i am trying to open an excel file on the clients pc using asp.net and vb.net.
i have specified
VB
Imports Microsoft.Office.Interop
in the aspx.vb file. and it works fine in the test environment.

but once i host it on the server (MS server 2003) having MS office 2003 installed, it throws an error. and when i check, it shows "microsoft.office.interop doesnt contain any public member or cannot be found"

and when i use a try catch block it throw the below error
VB
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)). 

Please help me out on this.

thanks
Joe
Posted
Updated 16-Sep-18 18:12pm
v3
Comments
Richard Deeming 18-Sep-18 15:46pm    
For anyone else who stumbles across this old question:

Code running on the server CANNOT use Office Interop to open a file on the client.

The file will open on the server, where nobody will ever see it.

And no, you can't use Office Interop on the client either.

The only way to open a file on the client is to write it to the response with the appropriate Content Type header. It is then up to the client to decide what to do with that file - you cannot force them to open it; you cannot force them to save it in a specific path; you cannot force them to save it at all.

Error Message:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0×80070005 (E_ACCESSDENIED)).
Solution:

This is a COM permissions problem.

Start > Run > dcomcnfg (or “mmc -32″ and then add the Component Services snap-in manually if you can’t find the app under step 3)
Navigate to Component Services > Computers > My Computer > DCOM Config
Locate the MS application giving you trouble (eg: “Microsoft Excel Application” for Excel or “Microsoft Word 97 – 2003 Document” for Word)
Right click > Properties
On the security tab: Select Customize under Launch and Activation Permissions and click Edit…
Add the account under which the site is running (eg: Network Service) and assign Local Launch & Local Activation permissions
Voila!

Error Message:

[COMException (0x800a03ec): Microsoft Excel cannot access the file '<filename>'. 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.
Solution:

This seems to be an issue with Excel/Word/etc not having access to a profile when being started via the interop route.

Open Windows Explorer
Depending on whether you installed a 32bit or 64bit version of office you will need to do one (or both) of the following:
32bit Office installation: Navigate to C:\Windows\System32\config\systemprofile
64bit Office installation: Navigate to C:\Windows\SysWOW64\config\systemprofile
Verify the folder "Desktop" exists (create it if it's not there)
Right click > Properties
On the security tab: Add the account under which the site is running (eg: Network Service) with default permissions (Read & execute; List folder contents; Read)
Voila!
 
Share this answer
 
Comments
Fayaz7Wonders 24-May-13 3:06am    
Hi,
Thanks a lot for ur solution.Its working but only when I am logged in to the Server.When I logged out same error when exporting Excel.Do u have any permanent solution for it.
J.Santichai 17-Feb-16 2:52am    
Well done for this solution :)
id8labs 27-Sep-17 0:44am    
Hi Wes Aday,
I am having same issue, on my local host when I am running the program exel and word file is creating and downloading properly but when I am publishing the code at server I am getting access denied error.
"Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))."
I searched on so many web sites and tried this
Start > Run > dcomcnfg
Then Component Services > Computers > My Computer > DCOM Config
On my local host I don't have "Microsoft Excel Application and Microsoft Word 97 – 2003 Document" and on my server I have these options. I selected all possible account that is available and gave full permission. Still facing the same problem. I need to add account or what?
Please help me in this. Thanks a lot.
Hi,

i got on how to do this. I had to set NETWORK SERVICES permission on the EXCEL DCOM in the server.

the next issue is, the NETWORK SERVICES locks the excel file the moment it is created and this creates opening, and deleting the excel file impossible.

well i found out that adding
VB
xlapp.quit()
solves the problem of the file being locked.

and its all fine now

thanks anyways
 
Share this answer
 
v2
1. Make sure that you have Office runtime installed on the server.
2. If you are using Windows Server 2008 then using office interops is a lenghty configuration and here are the steps.
Better is to move to Open XML or you can configure as below
• Install MS Office Pro Latest (I used 2010 Pro)
• Create User ExcelUser. Assign WordUser with Admin Group
• Go to Computer -> Manage
• Add User with below options
• User Options Password Never Expires
• Password Cannot Be Change
Com+ Configuration
• Go to Control Panel - > Administrator -> Component Services -> DCOM Config
• Open Microsoft Word 97 - 2003 Properties
• General -> Authentication Level : None
• Security -> Customize all 3 permissions to allow everyone
• Identity -> This User -> Use ExcelUser /password
• Launch the Excel App to make sure everything is fine
3.Change the security settings of Microsoft Excel Application in DCOM Config.
Controlpanel --> Administrative tools-->Component Services -->computers --> myComputer -->DCOM Config --> Microsoft Excel Application.
Right click to get properties dialog. Go to Security tab and customize permissions
 
Share this answer
 
Comments
Richard Deeming 18-Sep-18 15:42pm    
Considerations for server-side Automation of Office[^]
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

Not to mention the fact that the original question is totally misguided - code running on the server cannot open a file on the client by using Office Interop. The file will open on the server, where nobody will ever see it.

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