Q: How do I submit the InfoPath 2010 form programmatically to an external list?

To submit the InfoPath form programmatically to an external list, you will need to inspect the manifest.xsf, for starters.

+1
Tomek Stojecki, Ethan Wilanskyand 1 more

August 12, 2010

2 Min Read
ITPro Today logo in a gray background | ITPro Today

By Tomek Stojecki, Stefan Kowalewski, and Ethan Wilansky

Q: How do I submit the InfoPath 2010 form programmatically to an external list?

Problem: A common task when working with external lists in SharePoint 2010 is to use InfoPath 2010 forms to create or edit list items. In some situations you may need to submit the form programmatically using code behind and the submit event, where you become responsible for implementing the logic that submits the form data to its destination—in our case, an external list. Developers with InfoPath 2007 background are likely familiar with the following logic that submits the form to a list:

DataConnection dc = DataConnections\[“Data Connection Name”\];dc.Execute();// indicate successful operatione.CancelableArgs.Cancel = false;

The only tricky part is to figure out the right value for the data connection name. If your custom InfoPath 2010 form was created for an external list, it will contain “Main Data Connection” in the Data Connections window when inspected in InfoPath 2010 Designer. While specifying this value as the DataConnections indexer doesn’t throw an exception, the list doesn’t properly update its values after the form has been submitted.

Solution:
In order to submit the InfoPath form programmatically to an external list, you will need to inspect the manifest.xsf by extracting the source files from the .xsn file. In there you will find the xsf:bdcAdapter element and the attribute submitAdapterName with the value of “Main external list submit connection.” Use this value as an index to pass into the DataConnections collection instead, so the code in the submit event handler becomes:

DataConnection dc = DataConnections\[“Main external list submit connection”\];dc.Execute();// indicate successful operatione.CancelableArgs.Cancel = false;

We would like to thank Christopher Brotsos (Program Manager on the InfoPath team) for pointing us to this solution.

See all the SharePoint Q&As:

Sharepoint Q&A: How Can I Create an External List When SharePoint Throws an Unspecfied ASP.NET Error?

Sharepoint Q&A: How Can I Create an Action for an External Content Type in SharePoint?

Sharepoint Q&A: How to Make a Type String Type Descriptor a Required Field in the BDC Explorer

Sharepoint Q&A: Data Source Conflict

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like