How to programmatically print a browser-enabled infopath form - InfoPath Dev
in

InfoPath Dev

How to programmatically print a browser-enabled infopath form

Last post 10-06-2009 08:37 AM by philljenkins. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 10-06-2009 08:37 AM

    How to programmatically print a browser-enabled infopath form

    I didn't really get the answer I need from My last post on this topic, so I'm trying again, with a little more explanation of the circumstances. I'm really stuck on this so if there's anyone out there who can help please, please respond.

    Here's the scenario: On our SharePoint 2007 site I have a library of browser enabled infopath 2007 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 'Print View' button on the InfoPath Forms Services toolbar enabling users to view and print a special printer friendly view of the form data.

    What I've done (so far, in VS 2008):

    1. Created a feature which adds 'Bulk Print' to the Action menu of the form library
    2. When 'Bulk Print' is clicked it jumps to an aspx page which displays controls enabling the user to pick an appropriate date and click a 'Print' button.
    3. 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)

    Within PrintAForm I've tried various techniques for getting the form to print.

    • Using the InfoPath application as in the following code fragment

       string urlClaim = "http://domain/site/library/formname.xml"

       Microsoft.Office.Interop.InfoPath.Application ipApp = null;
       try
       {
        ipApp = new Microsoft.Office.Interop.InfoPath.Application();
        XDocument xdocClaim = ipApp.XDocuments.Open(urlClaim, (int)XdDocumentVersionMode.xdIgnoreDataAdaptersQueryFailure + (int)XdDocumentVersionMode.xdCanOpenInReadOnlyMode);
        xdocClaim.PrintOut();
       }
       catch (Exception ex)
       {
        AddMessage("Print failed with " + ex.Message);
       }
       finally
       {
        if (ipApp != null) ipApp.Quit(true);
       }

    This just never returns from the call to open the form. And in fact, when I 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!

    • Using a 'WebBrowser' object and navigating to a url like http://domain/site/_layouts/FormServer.aspx?XmlLocation=site/formname.xml&OpenIn=Browser but the call to Navigate never returns. And this technique does not allow me to change to the correct print view anyway.

            browser = new WebBrowser();
            browser.Visible = false;
            browser.Navigate(urlClaim);
            while (browser.IsBusy) System.Windows.Forms.Application.DoEvents();
            browser.Print();

    • Using an embedded XmlFormView control. But I can't figure out how to get it to change views and then print.

    I don't think I'm asking for much. How can 'PrintAForm' actually cause a form to be printed? Anyone got ANY ideas?

    Cheers

    Phill

     

Page 1 of 1 (1 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.