I am trying to read an .xls
file that is downloaded from a 3rd party site. I will not be processing the file everyday, so I can't change the format to .xlsx
before uploading the file.
I keep getting the following error:
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)).
I am using a vb.net
site with IIS7
.
The Application Pool logs in with my user and my user is an Administrator on the server with access to everything.
I have done the following:
- Office is installed on the HOST machine
- I have gone into
DCOMCNFG
and made sure that theLaunch and Activation Permissions
,Access Permissions
andConfiguration Permissions
have full control with my login account. - The server has x64 architecture, and I also have Office x64 installed
- I've confirmed that the folder
C:\Windows\SysWOW64\config\systemprofile\Desktop
as well asC:\Windows\SysWOW64\config\systemprofile\Desktop
does exist. - I know that
C:\Windows\SysWOW64\config\systemprofile\Desktop
is for x86 architecture but I made sure it was there just in case the system wanted to use it.
This is what my code looks like:
Imports genlib
Imports Excel = Microsoft.Office.Interop.Excel
Partial Class HeadOffice_OpperationalParameters_FailedBranches
Inherits System.Web.UI.Page
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
Protected Sub btnRunReport_Click(sender As Object, e As EventArgs) Handles btnRunReport.Click
If fuReport.HasFile = False Then
ClientScript.RegisterClientScriptBlock(Me.GetType, "", "alert('Upload a file to process.');", True)
Exit Sub
End If
Dim ReportFileName As String = Server.MapPath("~") & "FilesUploaded\" & fuReport.FileName.Replace(".XLS", "_" & Today.ToString("yyyy.MM.dd") & "_" & TimeOfDay.ToString("HH.mm.ss") & ".xls")
fuReport.SaveAs(ReportFileName)
Dim xlApp As Excel.Application 'Here
Dim xlWorkbook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
Try
'=================================================
' ERROR OCCURS ON NEXT LINE
'=================================================
xlApp = New Excel.ApplicationClass
xlWorkbook = xlApp.Workbooks.Open(ReportFileName)
xlWorksheet = xlWorkbook.Worksheets("RptTransactionDetail")
BrowserWrite(xlWorksheet.Cells(2, 2).value, True)
xlWorkbook.Close()
xlApp.Quit()
Catch ex As Exception
ClientScript.RegisterClientScriptBlock(Me.GetType, "", "alert('" & ex.Message.Replace("'", "\'").Replace(vbCr, "\r").Replace(vbLf, "\n") & "');", True)
Exit Sub
End Try
releaseObject(xlApp)
releaseObject(xlWorkbook)
releaseObject(xlWorksheet)
End Sub
End Class
Can anyone tell me how to resolve this error, or what steps to take to identify the issue?
I have read most of the posts on stack overflow but there are too many to add each answer that I have looked at.