Previous Next

Thread: Using Word component from ASP.NET page question

Last post 04-25-2008 11:08 AM by Madness80. 7 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (8 items)

Sort Posts:

  • 04-23-2008, 4:08 AM

    Using Word component from ASP.NET page question

     I've an ASP.NET page to convert local .doc file to pdf using Word 2007. The code runs fine running within VS.NET. It was giving COM error 80070005 running using IIS instead VS.NET but I managed to fix it using DCOMCNFG and adding ASPNET user to it. The problem is the code comes to a stop while opening the .doc file. It doesn't give any exceptions, it doesn't seem to timeout, it just waits there. Can you give me any ideas what's wrong? The code stops at this .Open() line :


    ApplicationClass app = new ApplicationClass();
    object missing = System.Reflection.Missing.Value;
    object file = @"c:\test\test.doc";
    object f = false;
    object t = true;

    doc = app.Documents.Open(ref file, ref missing, ref f, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref f, ref missing, ref missing, ref missing, ref missing);

    object FileName = @"c:\test\word2pdf.pdf";
    object FileFormat = WdSaveFormat.wdFormatPDF;
    object Encoding = MsoEncoding.msoEncodingEBCDICEnglish;
    object LineEnding = WdLineEndingType.wdCRLF;

    doc.SaveAs(ref FileName, ref FileFormat, ref f, ref missing, ref f, ref missing, ref f, ref f, ref t, ref t, ref f, ref Encoding, ref f, ref f, ref LineEnding, ref f);

    Label1.Text = "ok.";

    object nosave = WdSaveOptions.wdDoNotSaveChanges;
    doc.Close(ref nosave, ref missing, ref missing);
    app.Quit(ref nosave, ref missing, ref missing);

     

  • 04-23-2008, 7:21 AM In reply to

    • Rovastar
    • Top 10 Contributor
    • Joined on 03-13-2008, 10:00 AM
    • London, UK
    • Posts 758

    Re: Using Word component from ASP.NET page question

    An 80070005 is a permissions error.

    So check permissions in the dcom

    See

    http://www.computerperformance.co.uk/Logon/code/code_80070005.htm

    and google 80070005 and dcom

    It could be IIS permissions I suppose.

    But try and get some more error info to narrow down your search?

    Most overused word in IT is 'should' as in 'That should work!?!'
  • 04-23-2008, 8:04 AM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Lawrenceville, NJ
    • Posts 4,083
    • IIS MVPs

    Re: Using Word component from ASP.NET page question

    FWIW, Microsoft does not support or recommend the use of Office in any server-side automation:
    http://support.microsoft.com/kb/257757

  • 04-23-2008, 2:08 PM In reply to

    Re: Using Word component from ASP.NET page question

    Rovastar:

    An 80070005 is a permissions error.

    So check permissions in the dcom

    See

    http://www.computerperformance.co.uk/Logon/code/code_80070005.htm

    and google 80070005 and dcom

    It could be IIS permissions I suppose.

    But try and get some more error info to narrow down your search?

     

     Thanks for the link. Although I managed to bypass permission error for the component maybe it's another error for something Word uses. I don't know..

     
    Anyway I found out something. When the page calls the component it immidiately adds and event to the event log. It's like this:

    "Type: Warning
    Source: Microsoft Office 12 Sessions
    Event ID: 7003
    Description: ID: 0, Application Name: Microsoft Office Word, Application Version: 12.0.4518.1014, Microsoft Office Version: 12.0.4518.1066. This session was terminated unexpectedly."

    It says it was terminated but I still see the winword.exe running in the background until I kill it. It's very weird and I still got to solve this. I appreciate any ideas.. 

  • 04-23-2008, 3:17 PM In reply to

    • tomkmvp
    • Top 10 Contributor
    • Joined on 03-20-2003, 10:27 AM
    • Lawrenceville, NJ
    • Posts 4,083
    • IIS MVPs

    Re: Using Word component from ASP.NET page question

    bakakensai:
    I appreciate any ideas.. 
    Switch to an appropriate server component for creating PDF's ...

     

  • 04-23-2008, 5:06 PM In reply to

    Re: Using Word component from ASP.NET page question

    I agree with Tom, switch to a different software solution.

    Having said that, if you REALLY need to get it to work here are some thing that you can try. Start with the sysinternals process monitor and look for any access denied errors. That may point you to some error. Word expects to be interacting with a human and is likely displaying a message box. You can trap that by creating the error instrument registry keys. http://msdn2.microsoft.com/en-us/library/bb521317.aspx

    My setup is W2K3/ASP/Word 2003. To get that to work, I had to create a local account named MTS. Using dcomcnfg set Word.Application to run as the launching user, but restricted to interactive and the MTS account. For the folder that the ASP was in, I configured that to use MTS instead of the IUSR account. I next had to create a dummy service using srvany from the resource kit. I set that service to run as the MTS user. That causes the HKU hive for MTS to be loaded. That's why it works under VS.NET, the registry for the current user is available because all of the processes execute as the account that you've logged on to the desktop with.

    Just to reiterate, this may not work for you and the next security patch might break it. Find another solution. We use this http://www.SoftArtisans.com/

     

     

     

  • 04-25-2008, 10:31 AM In reply to

    Re: Using Word component from ASP.NET page question

    Madness80:

     I next had to create a dummy service using srvany from the resource kit. I set that service to run as the MTS user.

    Can you please explain this? Did you do just a "instsrv dummyname srvany.exe" or did you also create a dummy .net service and set srvany to run it?

  • 04-25-2008, 11:08 AM In reply to

    Re: Using Word component from ASP.NET page question

    I used SC from the reskit to create the service. I have srvany just execute sleep which then terminates.

     sc create WordIusr start= auto  binpath= c:\windows\system32\srvany.exe displayname= "Word Dummy Service for MTS" obj= .\mts password= whatever

    reg add  HKLM\System\currentcontrolset\services\wordiusr\Parameters
    reg add  HKLM\System\currentcontrolset\services\wordiusr\Parameters\AppDirectory="c:\"
    reg add  HKLM\System\currentcontrolset\services\wordiusr\Parameters\Application="c:\utils\sleep.exe 3"

    Again, MS does not support this and it could break at any time. 

Page 1 of 1 (8 items)
Page view counter