Solved

Word.Application in ASP.NET

Posted on 2003-12-08
7
6,716 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

12 Experts available now in Live!

Get 1:1 Help Now