Error in creating Excel Object : Retrieving the COM class factory

You might have faced a problem while creating an object of MS Excel using

 

Excel.ApplicationClass xl = new Excel.ApplicationClass();

 

resulting in the following error.

 

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.

 

Possible reasons for it are that your ASPNET account doesnt have enough permissions to create that COM object so you have to grant permissions to the user which is accessing that COM object.

By default ASP.NET web applications run under the ASPNET account, if you are using impersonation than the <machine_name>IUSR_<machine_name> is used to run that application so in each case you have to grant permissions to the respective users

 

You can grant permissions to those accounts to access the COM object on Windows XP using the following steps:

 

 

Configure DCOM

  • Go to the Start-Run menu item.
  • Type in “DCOMCNFG” and hit enter.
  • This should load the “Component Services” MMC (you can also load from Administrative Tools – Component Services”
  • Expand “Component Services”
  • Expand “Computers”
  • Expand “My Computer”
  • Select the “DCOM Config” item
  • Select the “Microsoft Excel Application” item.
  • Right click and select Properties
  • Select the Security Tab
  • Under “Launch and Activation Permissions” select the “Customize” option.
  • Click the “Edit” button
    • Click the “Add” button to add a new account to the list.
    • On the dialog that is displayed click the Locations button

      (select the first item which is your computer name)

 

 

  • Click the OK button
  • On the dialog that is displayed enter “ASPNET” as the account name (make sure location is set to the name of the computer that IIS is on) onWindows XP
  • On the dialog that is displayed enter “IUSR_” as the account name if you are using impersonation (make sure location is set to the name of the computer that IIS is on) onWindows XP

 

 

  • Click the OK button
  • Now make sure you select the following options for the “ASP.NET Machine Account” or the account that is the application pool identity ( by default Network Service)

    • Local Launch : Allow
    • Remote Launch : [blank]
    • Local Activation : Allow
    • Remote Activation : [blank]

 

Click the OK button and test your web application again and it should work fine.

The above steps have been taken from the following URL and you can go through it for a more detailed walk through

http://blog.crowe.co.nz/archive/2006/03/02/589.aspx

Microsoft Office Excel cannot access the file

You might have experienced a problem while opening an excel file using

 

 

Excel.Workbook workBook = app.Workbooks.Open(Path, 0, true, 5, “”, “”, true, Excel.XlPlatform.xlWindows, “t”, false, false, 0, true, 1, 0);

 

and ended up with the following error

 

Microsoft Office Excel cannot access the file ‘\ExcelFile.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.

 

This problem occurs on IIS 5 and IE 6.

 

It is a known issue and Microsoft offers a hotfix for IE 6 to overcome this issue.

 

You can find a detailed description of the problem and the link to download the hotfix on