Solved

Word.Application in ASP.NET

Posted on 2003-12-08
7
6,728 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

733 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