Open word with infopath

V

virgul

Hi,

I have a little probleme I don't know if I can open word using a C#
code in infopath?

What I have done is:

-I have do an XSLT transformation for WordML

-I have succesfully tested the transformation (with XMLSpy) with the
form that I send with infopath.

What I try to do(my idea):

-Do the transformation with the XSLT and the current form
(I know how to do that with a webservice but not with infopath)

-Open Word (I have found some explanation but that doesn't work)

For this idea it's better to do a webservice or do that in the infopath
form?

Can you say me what is the syntax (in C#) for in the infopath form code
capture the XML (that I have fill out) in a IXMLDomNode?

If you have any suggest, idea, link or anything else don't forget to
post!! I know I ask lot of things but If you can help me in one things
post!

Thanks for your help!!!

++

Thierry
 
G

G. Tarazi

You must have the Microsoft Office 2003 SDK for VS.NET 2003 (the one
available for MSDN subscribers only)



So; opening word from InfoPath should be simple,



using Office = Microsoft.Office.Core;

using Word = Microsoft.Office.Interop.Word;



object missing = Type.Missing;

object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;



Word.ApplicationClass wApp = new Word.ApplicationClass();

object objPaFileName = "the file path here";

Word.Document document = wApp.Documents.Open(ref objPaFileName, 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);



document.Close(ref doNotSaveChanges, ref missing, ref missing);

wApp.Quit(ref doNotSaveChanges, ref missing, ref missing);



But having both products working together in the real world is not that
easy, just getting this code to run the first time is not simple, trusted
forms, security exceptions, etc.



Having Microsoft Word as part of a web service is much easier (but not
supported by Microsoft, but who cares anyway, the supported products, like
InfoPath on PC, have tons of bugs, you will realize the first one of them
when your combo boxes loose their conditional formatting), in Windows 2003
you must create a user name that is an admin on the computer, then login
with this user name, start word and work with it, just to open it for the
first time.



Then create an application pool with the new admin user name / password
(which means less security I know, but if you find another way, I would love
to here about it), and connect your web service to it.



Then use the above code, it should work fine (you must have the sdk
installed, and reference the word/.net assemblies), if it does not, you
should start enabling the disabled by default option in the over secured
Windows 2003, until it works.



Estimated time to get them to work together: anything between 3 days to a
week or more, it depends on your experience.



And once you get them to work, the stupid words "ref missing" will become so
familiar; prepare yourself, you will be using it for a long time :).



This is another example of "Do less with more!"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top