interop >> Accessing Excel through ASP.NET (VB.NET)

by Amol » Tue, 04 Nov 2003 12:04:46 GMT

Hi All,

I am developing an application which requires opening an
Excel Workbook through ASP.NET code, raise a few events
to execute VBA code and then get results from Excel and
display them on web-page. I am getting 'Access is Denied'
error. I tried to give full permissions to ASPNET user to
Excel.EXE, the directory in which .xls file is stored and
even windows root, but the error still persists. It is
not able to execute the line 'MyXL = New
Excel.Application'.

I have spent a lot of time working on this problem. Any
help is appreciated.

I tried the following code:
Imports Microsoft.Office.Interop

Public Sub writeExcel(ByRef s As String, ByRef locn As
String)
Dim MyXL As Excel.Application
Dim MyWB As Excel.Workbook
MyXL = New Excel.Application
MyWB = MyXL.Workbooks.Open("C:/SomeBook.xls")
MyWB.Worksheets("Sheet1").Range(locn).Value = s
MyWB.Save()
MyWB.Close()
MyWB = Nothing
MyXL.Quit()
MyXL = Nothing
End Sub

ERROR:
Access is denied.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.UnauthorizedAccessException:
Access is denied.

ASP.NET is not authorized to access the requested
resource. Consider granting access rights to the resource
to the ASP.NET request identity. ASP.NET has a base
process identity (typically {MACHINE}\ASPNET on IIS 5 or
Network Service on IIS 6) that is used if the application
is not impersonating. If the application is impersonating
via <identity impersonate="true"/>, the identity will be
the anonymous user (typically IUSR_MACHINENAME) or the
authenticated request user.

To grant ASP.NET write access to a file, right-click the
file in Explorer, choose "Properties" and select the
Security tab. Click "Add" to add the appropriate user or
group. Highlight the ASP.NET account, and check the boxes
for the desired access.

Thanks.

Regards,
Amol Goel

interop >> Accessing Excel through ASP.NET (VB.NET)

by Frosty » Tue, 04 Nov 2003 21:27:58 GMT


From command prompt / start->run... type dcomcnfg

Select Component Services->Computers->My Compter->DCOM Config

Scroll down and select Microsoft Excel Applicaton

Right click on Microsoft Excel Applicaton and select properties.

Select the Security tab

In Launch Permissions group box click Edit button.

Add the appropriate user for your particular situation. In my case, I
selected MyDomainName\Domain Users.

Make sure that Allow check box is checked for your appropriate user.

Click OK

In Access Permissions group box click Edit button.

Add the appropriate user for your particular situation. In my case, I
selected MyDomainName\Domain Users.

Make sure that Allow check box is checked for your appropriate user.

Click OK

Excel interop will now work via asp.net

interop >> Accessing Excel through ASP.NET (VB.NET)

by Amol » Wed, 05 Nov 2003 00:50:24 GMT

hanx a lot Frosty .. its working now.

Amol

Config
properties.
In my case, I
appropriate user.
In my case, I
appropriate user.
message
an
Denied'
to
and
resource
or
application
impersonating
be
the
or
boxes

Similar Threads

1. RE : Accessing Excel through ASP.NET (VB.NET)

Hi,

Use <identity impersonate="true"/> in web.config and Run 
the application under a seperate account with permissions 
to Excel.

Thanks,
Gopi
>-----Original Message-----
>Hi All,
>
>I am developing an application which requires opening an 
>Excel Workbook through ASP.NET code, raise a few events 
>to execute VBA code and then get results from Excel and 
>display them on web-page. I am getting 'Access is 
Denied' 
>error. I tried to give full permissions to ASPNET user 
to 
>Excel.EXE, the directory in which .xls file is stored 
and 
>even windows root, but the error still persists. It is 
>not able to execute the line 'MyXL = New 
>Excel.Application'.
>
>I have spent a lot of time working on this problem. Any 
>help is appreciated.
>
>I tried the following code:
>Imports Microsoft.Office.Interop
>
>Public Sub writeExcel(ByRef s As String, ByRef locn As 
>String)
>        Dim MyXL As Excel.Application
>        Dim MyWB As Excel.Workbook
>        MyXL = New Excel.Application
>        MyWB = MyXL.Workbooks.Open("C:/SomeBook.xls")
>        MyWB.Worksheets("Sheet1").Range(locn).Value = s
>        MyWB.Save()
>        MyWB.Close()
>        MyWB = Nothing
>        MyXL.Quit()
>        MyXL = Nothing
>End Sub
>
>ERROR:
>Access is denied. 
>Description: An unhandled exception occurred during the 
>execution of the current web request. Please review the 
>stack trace for more information about the error and 
>where it originated in the code. 
>
>Exception Details: System.UnauthorizedAccessException: 
>Access is denied. 
>
>ASP.NET is not authorized to access the requested 
>resource. Consider granting access rights to the 
resource 
>to the ASP.NET request identity. ASP.NET has a base 
>process identity (typically {MACHINE}\ASPNET on IIS 5 or 
>Network Service on IIS 6) that is used if the 
application 
>is not impersonating. If the application is 
impersonating 
>via <identity impersonate="true"/>, the identity will be 
>the anonymous user (typically IUSR_MACHINENAME) or the 
>authenticated request user. 
>
>To grant ASP.NET write access to a file, right-click the 
>file in Explorer, choose "Properties" and select the 
>Security tab. Click "Add" to add the appropriate user or 
>group. Highlight the ASP.NET account, and check the 
boxes 
>for the desired access.
>
>Thanks.
>
>Regards,
>Amol Goel
>.
>

2. How to read Excel file in asp/Asp.net/vb/vb.net - Excel

3. Opening word, excel, pp document under asp.net with VB.net code behind

hello,

how can i open word, excel, pp document witout the standard commandbar so that the user couldn't use the options "save, save as, ctrl+F and ctrl+S,...".

thanks for a quick answer.

4. VB.Net (in ASP.Net) won't create instance of Excel - Asp.Net