Refresh page after edit in InfoPath
When using InfoPath for editing data in you webapplications you run into a couple of tricky situations when beeing used to plain webdevelopment. One of these scenarios is when you want your webpage to refresh after having edited a record in some datasource with InfoPath. Typically you've implemented a view webpage and edit with InfoPath.
This sounds pretty uncomplicated, and I guess it is, but still it took me quite a while to figure out.
My first attempt was to use standard web techniques like opening a browser window pointing to the infopath form modally with showModalDialog and refreshing the hostpage on return. No luck. I was thinking about creating a custom hostpage utilizing iframes to open the document much like a lot of people do to handle pdfs, but I really don't like adhoc host'ish pages in my solution.
I also considered going all the way and serve my Infopath documents dynamically, but that would have been to big of a change to my current solution.
I went back and studied how the Sharepoint SDK suggests to solve this problem. Sharepoint makes use of a clientside component (INLAUNCH.DLL) to open InfoPath documents. The control is called OpenXMLDocuments. From the documentation I adopted the RefreshOnFocus approach from the Create sample and tried to modify the Edit sample with it to get the refresh. Problem was that InfoPath slightly lost focus during load of the XML document which forced a too early refresh of the hostpage when using the EditDocument2 method directly.
Then I read Westins blog and got the idea to se exactly what Sharepoint does on the "Edit in Microsoft Office Infopath" button. Westin also describes how to launch an InfoPath form from a Sharepoint page but this only includes create which seems to work slightly different from edit.
Adopting the call from the "Edit in Microsoft Office Infopath" button and combining it with the RefreshOnFocus approach lead me to the following working solution for refreshing a webpage after editing in InfoPath.
window.location.href = window.location;
window.onfocus = RefreshOnFocus;
Be aware that the clientside control must be present for this to work, but I assume it is installed with InfoPath (anyone care to assert this assumption regarding INLAUNCH.DLL?). The editDocumentWithProgID2 method is defined in the standard Sharepoint script includes.