The prerequisites for this post and the tasks covered are SharePoint 2010 and Microsoft Office
InfoPath Designer 2010 installed on your machine.
Having a good understanding about CAML(Collaborative Application Markup Language), a
knowledge of the methods of the SharePoint Lists web service would be really helpful.
To get more information about the SharePoint Lists web service:
Open IE navigate to "http://servername/_vti_bin/lists.asmx?WSDL"
(You will be able to see all the web methods associated with the Lists web service. For our
purpose we will be using UpdateListItemsweb method).
STEP 1. Create a Custom List in a SharePoint Site, 'Employee'. Also create some columns as
per your need.
Note that there will be a default column called 'Title' and lets not change it and keep it that way to
store EmployeeName, I've create EmployeeAddress, EmployeeNo, EmployeeEmail as columns
which are Single text.
STEP 2. Open Microsoft Office InfoPath Designer 2010 and select a Blank Form and click
Design Form. Then do as follows.
|Security and Trust|
|Renaming the button|
STEP 3. In SharePoint site under Employee list, in ribbon under List Tools select List and then select List Settings. In that page click Advanced Settings and select Allow management of content types to Yes.
STEP 4. Again go to List Settings click Metadata navigation settings and copy the list GUID.
|Copy list GUID|
STEP 5. Go back to InfoPath form right click on listID and paste GUID under value field.
STEP 6. Open Notepad and type,
<?xml version="1.0" encoding="UTF-8" >?
<Method ID="1" Cmd="New">
<Field Name='Title' />
<Field Name="EmployeeAddress" />
<Field Name="EmployeeNo" />
<Field Name="EmployeeEmail" />
Save the file as an xml file and name it Submit.xml.
STEP 7. Now lets create Data Connections. Go to InfoPath form and click Manage Data Connections. First we need to create a Receive Data connection. I am naming it as 'Submit'.
|Browse for the created Submit.xml file|
|Naming the connection as 'Submit'|
STEP 8. Now we need to create a Submit Data Connection. Again in Manage Data Connections click Add.
|To a Web Service|
|Include : Text and child elements only|
|Include : XML Subtree, including selected element|
|Web Service Submit|
|Edit Form Code|
STEP 9. Click Edit Form Code and btnSubmit_Clicked event will be created. In that block, type the following code.
XPathNavigator root = MainDataSource.CreateNavigator();
// Retrieve the values for the separation list item
string listID = root.SelectSingleNode("/my:myFields/my:listID", NamespaceManager).Value;
string eNameDS = root.SelectSingleNode("/my:myFields/my:EmployeeName", NamespaceManager).Value;
string eAddressDS = root.SelectSingleNode("/my:myFields/my:EmployeeAddress", NamespaceManager).Value;
string eNoDS = root.SelectSingleNode("/my:myFields/my:EmployeeNo", NamespaceManager).Value;
string eEmailDS = root.SelectSingleNode("/my:myFields/my:EmployeeEmail", NamespaceManager).Value;
if (listID == null)
//This is CAML xml file. it contains batch and method nodes
XPathNavigator batch = DataSources["Submit"].CreateNavigator();
DataConnections["Web Service Submit"].Execute();
catch (Exception ex)
STEP 10. And finally thats all. Preview the form and try submitting the data. After that publish the form and upload the form template into SharePoint and start using.
There are few important things to remember carefully.
- There is a significant difference between Display name and the Field name. When we are doing the coding we are using the value under the Field name. If you can remember, I have mentioned to keep the default 'Title' column as it is, because if we rename the 'Title' column it will just change the display name. The Field name will be remain as 'Title'.
- No of updating list fields should be the same as no xml field names.
- When I am creating columns in SharePoint list, if you can remember I have included no spaces between words. Thats because it will add characters into Field names. So when we are referring to Field names from looking at Display names, the Field name is actually differs from the Display name.
- List fieldname should be same as xml fieldname.
- Make sure when creating the Submit Data connection 'Web Service Submit' to select following things,
- listName - listID : Include : Text and Child elements only
- updates - Batch : Include : XML subtree, including selected element