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

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 operation
e.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 operation
e.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

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish