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):
-
Created a feature which adds 'Bulk Print' to the Action menu of the form library
-
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.
-
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.
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();
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