maandag, januari 15, 2007

Handle the InfoPath Forms Services by yourself (in a Custom WebPart to view a web-enabled Infopath 2007 Form)

To understand this post well, please go through this post first:
- Hosting the InfoPath 2007 Form Editing Environment in a Custom Web Form

Sometimes you don't want to popup an error by InfoPath Forms Services (it will log this also in the EventLog), see image below. You want to catch the error in code and do some custom logging (or other stuff)

I will use the example when a dataconnection (webservices) in the form gives a time-out.

First keep in mind that we will bind the dataconnection-webservice to its control in code, so you have to deselect - Automatically retrieve data when form is opened (when adding a data-connection in InfoPath). Also don't forget to link the control with the dataconnection in infopath designer

What we gonna do in code:
- Add a handler that will get you into the Initialize methods of the XmlFormView
- Get the right dataconnection, execute it (so it will get the data and bind to the control)
- Add a "try/catch" block around this code

The code:

void viewform_Initialize(object sender, InitializeEventArgs e)
DataConnection dc = _viewform.XmlForm.DataSources["GetGAL"].QueryConnection;
catch (System.Net.WebException webEx)
//Log, ...
catch (Exception ex)
Logger.Log(ex, ...);

Some other InfoPath blogs:

Geen opmerkingen: