Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

For our document printing needs i am writing a new service application (in c#) that needs to print documents in word templates. The concept is based on an old c++ based application we had in the late nineties. What the service basically does is, it open a word document with a macro-function called printDocument(strFile as string, templateName as string). The function parses the file and prints the content thru bookmarks in a template, both passed in the function parameters. This used to work 20 years ago.

I have all code written again in c# and it runs fine in my Visual Studio environment. However if i try to run it as a service then when opening the document with the macro an error is thrown.

I need some help in understanding if this is still possible?

Based on this article i understand it is not anymore: https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office

Thanks for the help in advance.

What I have tried:

Searched the internet for similar solutions
Posted
Comments
OriginalGriff 22-Aug-19 1:44am    
"An error is thrown" is one of the error reports we get quite often, and it's always completely useless - it tells us nothing about your problem other than "I have a problem" and we knew that because you are asking a question!

What did it do that you didn't expect, or not do that you did?
When did it do it?
Are there any error messages? What were they? What code did they relate to?
What did you do to make it do that?
What have you tried to do to find out why?
What were the results?
What help do you need?

These are all questions we need an answer to - or we can't help you at all!
Avoird 22-Aug-19 13:15pm    
Hi,
To be more specific then. The function below returns null in the object wordDocument:

object wordDocs = GetProperty("Documents", wordApplication);

wordDocument = InvokeMember("Open", wordDocs, new object[]{fileName, missing,
isReadonly, missing, missing, missing,
missing, missing, missing, missing,
missing, isVisible});

When I run the logic in my test Console application then the word document I am trying to open is opened and I can execute a macro inside.
When I run the application inside a service project in debugmode in visual studio I can also open the word document and run a marco.
Then when compiling to release mode and create a Setup project to install the application as a service then when starting the service from services manager it does not open the word doc instead, InvokeMember returns a null in the object.
I am developing this application in order to replace our Adobe Central Server and Adobe Designer software. Adobe stopped their support 7 years ago.

What have I done so far to try to resolve this...
Several solutions proposed on forums such as:
* creating a desktop folder in the Systems profile.
* Changing the DCOM impersonation from launching to interactive (which does not make sense of course when running as a service).

The service needs to run on W2016 with at latest MS Office word.

So I need some help to understand why my service is not able to launch the document I am trying to open and why the function returns a null value.

I hope this is detailed enough.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900