?
Solved

Word.Application in ASP.NET

Posted on 2003-12-08
7
Medium Priority
?
6,739 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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 1000 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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

765 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