Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / June 2006

Tip: Looking for answers? Try searching our database.

Converting an InfoPath form to Word 2003 and emailing it

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
daniel1107@hotmail.com - 21 Jun 2006 19:17 GMT
Hello,

New to the groups, and I have a question. I could not find a post
similar to this.

What I am trying to do is submit an InfoPath form with Rules and Custom
Code. The Custom Code needs to run first and convert my form to
Microsoft Word 2003. Then my rules are to send the file created (word
document) in an email to select people and also send the document to a
SharePoint document library.

I have the rules working fine. My question is on the custom code. I am
using this code below:

If the submit operation is successful, set
            // e.ReturnStatus = true;
            // Write your code here.
            // Write your code here.
            // First create a COM DOM and load the XSL resource file into that
DOM.
            IXMLDOMDocument domDocument = thisXDocument.CreateDOM();
            domDocument.load("printversion.xsl");

            // Create an XmlDocument object and load the XML of the DOM.
            XmlDocument xsltDocument = new XmlDocument();
            xsltDocument.LoadXml(domDocument.xml);

            // Load the InfoPath XML into an XmlDocument object.
            XmlDocument infoPathDocument = new XmlDocument();
            infoPathDocument.LoadXml(thisXDocument.DOM.xml);

            // Load the XSL XmlDocument object into an XslTransform object.
            XslTransform xslt = new XslTransform();
            xslt.Load(xsltDocument.CreateNavigator(), new XmlUrlResolver(),
                this.GetType().Assembly.Evidence);

            // Create an output XmlDocument object and load the results of the
transform.
            XmlDocument outputDoc = new XmlDocument();
            outputDoc.Load(xslt.Transform(infoPathDocument.CreateNavigator(),
null, new XmlUrlResolver()));

            // Instantiate Word and insert the output XmlDocument object into a
new document.
            object missing = System.Reflection.Missing.Value;
            Word.Application wordApp = new Word.ApplicationClass();
            Word.Document oDoc = new Word.DocumentClass();
            oDoc = wordApp.Documents.Add(ref missing, ref missing, ref missing,
ref missing);
            wordApp.Selection.Range.InsertXML(outputDoc.OuterXml,ref missing);
            wordApp.Visible = true;

which works fine. But when the word document opens, the xml does not
format to the way the InfoPath form looked.

Anybody have some ideas? Im thinking something needs to be done to the
code before it spits the XML to the document but I dont know what.

Also, how would I implement telling InfoPath to send the Word document
in the Rule instead of the InfoPathxsn form?

Thanks, any help would be greatly appreciated.
Greg Collins [InfoPath MVP] - 30 Jun 2006 20:29 GMT
Have you looked into the Word Print View feature (see the InfoPath SDK)... I don't know that it will necessarily work for you--but it might give a push in the right direction.

I don't recall if it pops open word and waits for you to print (if so, you can then mail it) or if it attempts to auto-print and then shut down Word right after.

Signature

Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Visit InfoPathDev ( http://www.InfoPathDev.com )

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.