Solved

Word.Application in ASP.NET

Posted on 2003-12-08
7
6,725 Views
Last Modified: 2013-11-25
This is a tough one and worth 500 points.  If you're not familiar with the Word.Application in .NET, stop reading now :)

Reference this article:
http://www.codeproject.com/aspnet/wordapplication.asp

object fileName = "c:\\database\\test.doc";
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
Word.ApplicationClass oWordApp = new Word.ApplicationClass();
Word.Document oWordDoc = oWordApp.Documents.Open(ref fileName,
                            ref missing,ref readOnly,
                            ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref missing,
                            ref missing, ref missing, ref isVisible,
                            ref missing,ref missing,ref missing);

oWordDoc.Activate();
oWordApp.Selection.TypeText("This is the text");
oWordApp.Selection.TypeParagraph();
oWordDoc.Save();
oWordApp.Application.Quit(ref missing, ref missing, ref missing);

Now, the problem is that when my code is run on the Web server (works fine on my development machine), I get the following error:

Description: Command failed
Stack Trace: at Word.Documents.Open(Object& FileName, Object& ConfirmConversions, Object& ReadOnly, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Format, Object& Encoding, Object& Visible, Object& OpenAndRepair, Object& DocumentDirection, Object& NoEncodingDialog)

I am *absolutely* certain that the path to the document is correct (I tested that about 10 times already).  Also, the exact same version of word is running on both my development machine and the Web server v10.2627.3501 SP-1.  The ASP.NET account has full permissions on the opening-file in question.

In DCOMCNFG, the ASP.NET account was granted launch permissions on Microsoft Word Application.
0
Comment
Question by:SirCaleb
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:roverm
ID: 9902655
Place the document in your webroot, then set the path to it and try again.
Then you'll be sure that your code is working ok on your webserver.
0
 
LVL 2

Author Comment

by:SirCaleb
ID: 9905432
It doesn't matter where the document is located -- it doesn't work.  The document has full access permissions by "everyone" as well.

I updated my local and the Web server's version of Office to SP2 with all security updates as well.

Additionally, I cannot even create (on the server) a document using the simplest code (in VB.NET):

Dim WordApp As New Word.ApplicationClass
Dim WordDoc As Word.Document = WordApp.Documents.Add()
WordDoc.Activate()
WordApp.Selection.TypeText("This is the text")
WordApp.Selection.TypeParagraph()
WordDoc.SaveAs("c:\test.doc")
WordApp.Application.Quit()

This *should* create a new word document but instead it fails on line 3 because WordDoc = Nothing (on the Web server) ... works fine on my local machine.
0
 
LVL 12

Expert Comment

by:roverm
ID: 9906480
Then it has to do something with userrights.
Did you try by creating a Word object using CreateObject?

Dim WordApp As Object = Server.CreateObject("word.application")
Dim WordDoc As Object = WordApp.documents.add

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 2

Author Comment

by:SirCaleb
ID: 9906732
roverm, I tried that.

I actually figured it out.  In dcomcnfg.exe, I set the Word Document Application to always run under the same account in the Identity Tab instead of the "Launching User" (ASP.NET) ... and that works.  So, it seems there was a hand-off at some point between ASP.NET and Interactive User or something bizarre causing the permissions issue.
0
 
LVL 12

Accepted Solution

by:
roverm earned 500 total points
ID: 9906795
So it was userrights after all!
Glad to see that it's solved.

Can you please close the question (now it's solved)?
Thanks!

D'Mzz!
RoverM
0
 
LVL 2

Author Comment

by:SirCaleb
ID: 9907141
I'll just give you the points for the heck of it.
0
 
LVL 12

Expert Comment

by:roverm
ID: 9907775
*lol*
That's not what I meant but thanks! I meant by closing that you asked CS to PAQ and refund.
But I like this as well! ;-)

D'Mzz!
RoverM
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now