Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Word.Application in ASP.NET

Posted on 2003-12-08
7
Medium Priority
?
6,748 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

610 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