Solved

Can I use the word object from within a webservice?

Posted on 2008-10-23
9
496 Views
Last Modified: 2008-11-03
I'm trying to do a proof of concept to see if I can do some very basic word automation from within a webservice.  The problem I have is that after I have created an instance of the Word Appliation I am unable to open any files.  The Document that I am trying to get is always null.  Any ideas whats wrong? Is what I'm trying to do even possible?

In my code below you'll see that all I'm trying to do is create an instance of word (which succeeds), and then open the document (which fails and gives me a null reference). (The doc.Activate is only to cause an the null reference error)
private void PrintDocument(string safeFileName)

{

	Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();

	// Open Doc

	object filename = safeFileName;

	Microsoft.Office.Interop.Word.Document doc = app.Documents.OpenNoRepairDialog(ref filename, ref _missing, ref _missing, ref _missing, ref _missing, ref _missing, ref _missing,

																											ref _missing, ref _missing, ref _missing, ref _missing, ref _missing, ref _missing, ref _missing,

																											ref _missing, ref _missing);

	doc.Activate(); // fails here because doc == null

	app.Quit(ref _missing, ref _missing, ref _missing);

}

Open in new window

0
Comment
Question by:guxiyou
  • 5
  • 4
9 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 22794712
Using Office automation from on web server is a really bad idea. try the trial version of http://www.aspose.com/categories/file-format-components/aspose.words-for-.net-and-java/default.aspx
0
 

Author Comment

by:guxiyou
ID: 22796352
Hmm, I'll give Aspose a try.  Why is running office automation from a web server such a bad idea? The service will only be used on a local LAN and for processing after hours.
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 22796377
from http://support.microsoft.com/kb/257757

Although such programmatic development can be implemented on a client system with relative ease, a number of complications can occur if Automation takes place from server-side code such as Microsoft Active Server Pages (ASP), ASP.NET, DCOM, or a Windows NT service.
0
 

Author Comment

by:guxiyou
ID: 22797311
I gave Aspose a try.  Unfortunately I found that Aspose did not preserve the formatting very well, and that the print quality of the documents wasn't very good.  Do you have any other suggestions of third-party tools that might be helpful?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:guxiyou
ID: 22797331
One big requirement I we have is that the documents we produce with this tool need to work well with Word and look professional.  If we lose formatting every time we move back and forth that isn't going to work very well ;)
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 22797397
I am using Aspose and just about everything that is available in Word is available in their tool.

If you find features that are missing, you can ask in their forum. They have added a couple of features for me in the .Cells product. They are very responsive.
0
 

Author Comment

by:guxiyou
ID: 22797422
Have you found that the documents you've manipulated using Aspose look the same as their Word counterparts? The quick test that I did seemed to indicate that spacing wasn't preserved very well.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 22797501
I have played only with Excel and PDF documents.

Even if you are only playing with the trial, post a question on their forum and you will get your problem solved.
0
 

Author Comment

by:guxiyou
ID: 22867621
I've tried Aspose, but there still seems to be a problem when trying to print from within a webservice. I'll keep trying, but I guess you've really answered my question already. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Error - Add Failed 12 78
What's the most efficient way to load up a couple of large table in C#? 5 32
Two different visual studio versions 3 21
Error in script 11 44
It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

929 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

11 Experts available now in Live!

Get 1:1 Help Now