Link to home
Start Free TrialLog in
Avatar of guxiyou
guxiyou

asked on

Can I use the word object from within a webservice?

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

Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

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
Avatar of guxiyou
guxiyou

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of guxiyou

ASKER

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?
Avatar of guxiyou

ASKER

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 ;)
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.
Avatar of guxiyou

ASKER

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.
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.
Avatar of guxiyou

ASKER

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