<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Browser Forms</title><link>https://www.infopathdev.com:443/forums/40.aspx</link><description>For browser form specific questions</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>How to programmatically print a browser-enabled infopath form</title><link>https://www.infopathdev.com:443/forums/thread/47624.aspx</link><pubDate>Tue, 06 Oct 2009 15:37:46 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:47624</guid><dc:creator>philljenkins</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/47624.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=40&amp;PostID=47624</wfw:commentRss><description>&lt;p&gt;I didn&amp;#39;t really get the answer I need from &lt;a title="My last post" href="http://www.infopathdev.com/forums/t/13316.aspx"&gt;My last post&lt;/a&gt; on this topic, so I&amp;#39;m trying again, with a little more explanation of the circumstances. I&amp;#39;m really stuck on this so if there&amp;#39;s anyone out there who can help please, please&amp;nbsp;respond.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the scenario: On our SharePoint 2007&amp;nbsp;site I have a library of browser enabled infopath 2007&amp;nbsp;forms and I want to able to print, in bulk, a bunch of the forms, based on a date field in the form. For example, print all forms for which the date field = 2009/10/18. The form template is fully trusted and correctly uploaded to the SP site by a site admin. The form itself works fine from a browser and displays a &amp;#39;Print View&amp;#39; button on the InfoPath Forms Services toolbar enabling users to view and print a special printer friendly view of the form data.&lt;/p&gt;
&lt;p&gt;What I&amp;#39;ve done (so far, in VS 2008):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div&gt;Created a feature which adds&amp;nbsp;&amp;#39;Bulk Print&amp;#39; to the Action menu of the form library&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;When &amp;#39;Bulk Print&amp;#39; is clicked it jumps to an aspx page which displays controls enabling the user to pick an appropriate date and click a &amp;#39;Print&amp;#39; button.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;The OnClick event handler for the print button uses a CAML query to find all items in the library for the given date and calls PrintAForm(SPListItem itemAForm)&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Within PrintAForm I&amp;#39;ve tried various techniques for getting the form to print.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;Using the InfoPath application as in the following code fragment&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;string urlClaim =&amp;nbsp;&amp;quot;&lt;a href="http://domain/site/library/formname.xml"&gt;http://domain/site/library/formname.xml&lt;/a&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Microsoft.Office.Interop.InfoPath.Application ipApp = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ipApp = new Microsoft.Office.Interop.InfoPath.Application();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;XDocument xdocClaim = ipApp.XDocuments.Open(urlClaim, (int)XdDocumentVersionMode.xdIgnoreDataAdaptersQueryFailure + (int)XdDocumentVersionMode.xdCanOpenInReadOnlyMode);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xdocClaim.PrintOut();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;catch (Exception ex)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AddMessage(&amp;quot;Print failed with &amp;quot; + ex.Message);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;finally&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (ipApp != null) ipApp.Quit(true);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;This just never returns from the call to open the form. And in fact, when I&amp;nbsp;manually run InfoPath and try to open the same url it fails, complaining that the form is not fully trusted - but the form is trusted! &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;Using a &amp;#39;WebBrowser&amp;#39; object and navigating to a url like &lt;a href="http://domain/site/_layouts/FormServer.aspx?XmlLocation=site/formname.xml&amp;amp;OpenIn=Browser"&gt;http://domain/site&lt;a href="http://portal.dev.envirolink.local/admin/tec/_layouts/FormServer.aspx"&gt;/_layouts/FormServer.aspx&lt;/a&gt;?XmlLocation=site/formname.xml&amp;amp;OpenIn=Browser&lt;/a&gt;&amp;nbsp;but the call to Navigate never returns. And this technique does not allow me to change to the correct print view anyway.&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; browser = new WebBrowser();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; browser.Visible = false;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; browser.Navigate(urlClaim);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (browser.IsBusy) System.Windows.Forms.Application.DoEvents();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; browser.Print();&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;Using an embedded XmlFormView control. But I can&amp;#39;t figure out how to get it to change views and then&amp;nbsp;print.&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;I don&amp;#39;t think I&amp;#39;m asking for much. How can &amp;#39;PrintAForm&amp;#39; actually cause a form to be printed? Anyone got ANY ideas?&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
&lt;p&gt;Phill&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>