Submit data from Infopath form to SharePoint list using SharePoint object model

SharePoint deveopment training course

In this post, we will discuss how to Submit data from Infopath form to SharePoint list using the SharePoint object model. Also, you can check out my previous posts on:

Update a list item using JavaScript object model in SharePoint 2013

Difference between Apps and Solutions in SharePoint 2013

Show SharePoint list data in repeating table in InfoPath 2010

Here we have a textbox and a submit button. On click of the submit button, we will save the textbox data to the SharePoint list.

Right click on the button, go to Button Properties… From the Properties window click on Edit Form Code button… This will open the visual studio where we will write the code.

Here we will use the SharePoint object model. So first add a reference to the MicroSoft.SharePoint.dll by going to the References folder and right click and click add references. The dll will be available under.Net category.

Once added then write the using statement like below:

using Microsoft.SharePoint;

Write below code in the button click event:

using (SPSite thisSite = new SPSite(ServerInfo.SharePointListUrl.ToString()))
using (SPWeb web = thisSite.OpenWeb())
web.AllowUnsafeUpdates = true;

SPList listEmployees = web.Lists[“Employees”];

if (list != null)
SPListItem item = list.Items.Add();

item[“Title”] = MainDataSource.CreateNavigator().SelectSingleNode( “//my:field1”,NamespaceManager).Value;


web.AllowUnsafeUpdates = false;

Now publish the infopath form and then it will add the textbox value to the SharePoint list.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)


About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site

View all posts by Bijay Kumar →