« Previous Next »

Thread: Error using Excel from asp.net, under IIS7.

Last post 07-02-2008 5:55 PM by StevenM. 3 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (4 items)

Sort Posts:

  • 07-01-2008, 11:34 AM

    • StevenM
    • Not Ranked
    • Joined on 05-17-2005, 9:59 AM
    • Posts 2

    Error using Excel from asp.net, under IIS7.

    I am running an older ASP.NET web application on a new computer that has Vista 64 with IIS7 and Office 2007 installed.  The application has some code in an asp.net page that access the Excel.Application objects and this code is now failing on this new system.

    I created a small test application using the ASP.NET Web application and dropped in enough of the code to duplicate the problem. (Code shown below)

    At first the new sample web app's properties were set to use the "Use Visual Studio Development Server" and with that server the excel code works fine. When I switch to "Use IIS Web server" the code begain to fail.

    At first the virutal directory was using the DefaulAppPool, and with that setting the following line was failing with a {"Cannot create ActiveX component."} error.
      loExcelApp = CreateObject("Excel.Application")

    Then I changed the application pool for the WebApplication virtual directory to be the "Classic .NET AppPool" which is configured for .NET Framework Version v2.0 and Enable 32-Bit Applications set to True. It also has the Identity set to a local admin account. 

    Now it gets through most of the excel code but ultimately fails on the .SaveAs line...

    oWorkbook.SaveAs("C:\MyFile1.xls")

    SaveAs method of Workbook class failed
    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.Runtime.InteropServices.COMException: SaveAs method of Workbook class failed


    I have also tried using early binding for excel instead of the late binding and also tried compiling the applicatin as x86, but these changes made no difference with the error.

    So at this point I am trying to figure out if this is a problem with IIS 7, vista 64 or Office 2007.

    Any insite into how to resolve this would be appreciated.

    -- Steven

     

    Dim oExcelApp As Object = Nothing

    Dim oWorkbooks As Object = Nothing

    Dim oWorkbook As Object = Nothing

    Dim oSheet As Object = Nothing

    oExcelApp = CreateObject("Excel.Application")

    ' Create an excel workbooks object

    oWorkbooks = oExcelApp.Workbooks

    ' Create an excel workbook

    oWorkbook = oWorkbooks.add

    ' Initialize the work sheet.

    oExcelApp.DisplayAlerts = False

    oSheet = oExcelApp.ActiveSheet()

    oSheet.Name = "MyTestSheet"

    oSheet.Cells(1, 1).Value = "Some Data"

    ' Save the file, this is where it fails.

    oWorkbook.SaveAs("C:\MyFile1.xls")

  • 07-01-2008, 11:32 PM In reply to

    Re: Error using Excel from asp.net, under IIS7.

    One thing, are you using the IUSR as the anonymous vs. local system? Or are you inheriting the app pool user from anonymous.  The CreateObject seems "odd" from a .NET application, then again, I've not done indepth coding with Excel and .NET.  It's more an observation.  I would enable some audit failure logging and see if anything turns up.  Also, use process monitor and see if any registry, file / folder security issues.  That would rule out the machine and some configuration.

    http://weblogs.asp.net/steveschofield/archive/2008/03/07/detecting-permission-issues-using-auditing-and-process-monitor.aspx

     

    Steve Schofield
    Windows Server MVP - IIS
    http://weblogs.asp.net/steveschofield


    http://www.IISLogs.com
    Log archival solution
    Install, Configure, Forget
  • 07-01-2008, 11:36 PM In reply to

    Re: Error using Excel from asp.net, under IIS7.

    I apologize for not being more clear in my 1st sentence, here is an image showing the screen about the anonymous user.  http://www.iislogs.com/images/anonymousIIS7.jpg

    Start > Run > Inetmgr > SiteName > IIS section > Authentication > Right click on Anonymous.

    Steve Schofield
    Windows Server MVP - IIS
    http://weblogs.asp.net/steveschofield


    http://www.IISLogs.com
    Log archival solution
    Install, Configure, Forget
  • 07-02-2008, 5:55 PM In reply to

    • StevenM
    • Not Ranked
    • Joined on 05-17-2005, 9:59 AM
    • Posts 2

    Re: Error using Excel from asp.net, under IIS7.

    Thank you for your quick reply. 

    I have the Anonymous Authentication Credentials set to Specific User and that user is an user who has admin on the workstation.

     I also tried changing it to Application pool identity and that made no difference for the error.

    -- Steven 

Page 1 of 1 (4 items)
Microsoft Communities