There are two methods we can use to insert a list-item out-of-the box. Those methods are using the web-service and using the object model.
The consideration when to use the method is whether the form will be executed within SharePoint context or it will be executed outside SharePoint.
If you are going to use within the SharePoint context, you can use Object-Model or Web-service otherwise.
Today, I’ll show on how to insert a list-item to a list in SharePoint using the object model.
STEP 1: CREATE A BLANK FORM IN INFOPATH FORM.
STEP 2: CREATE A CUSTOM LIST WITH THE FOLLOWING FIELDS. (Employee Details)
| FIELD’S NAME | TYPE | InfoPath Field’s name | Data Source’s type | |
| First_Name | Single Text | Txt_FirstName | Textbox | |
| Last_Name | Single Text | Txt_LastName | Textbox | |
| Mobile_Number | Single Text | Txt_MobileNum | Textbox | |
| List Name: Employee Details | InfoPath form’s detail | |||
STEP 3: CREATE A DATA CONNECTION FROM INFOPATH.
- Create an InfoPath 2007’s form as the following picture.
![]() |
- Click Tools – Programming – Microsoft Visual Studio Tools for Applications
![]() |
-
We need to reference Microsoft.SharePoint.dll to our VSTA. It can be found under:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI
![]() |
-
Click Tools – Form Options – Security and Trust.
Tick off “automatically determined security level (recommended)” and change it to Full Trust.
Tick on “Sign this form template” – Create Certificate if you haven’t got a certificate yet.
![]() |
- Now let’s start the fun part. Right-Click – Properties on the submit button. Add the following function underneath the CTRLX_X_Clicked’s event.
| private void InsertListItem(string FirstName, string LastName, string MobNum){
SPSite Myportal = new SPSite(“http://your_servername”); SPWeb myWeb = Myportal.OpenWeb(); SPListCollection ListCollection = myWeb.Lists; SPList EmployeeDetails = ListCollection["Employee Details"];
SPListItem newItem = EmployeeDetails.Items.Add(); newItem["First_Name"] = FirstName; newItem["Last_Name"] = LastName; newItem["Mobile_Number"] = MobNum; newItem.Update();
//Disposing unused objects. Myportal.Dispose(); myWeb.Dispose(); } |
- Then add the following code inside the clicked’s event
| XPathNavigator main = MainDataSource.CreateNavigator();string _firstname = main.SelectSingleNode(“/my:myFields/my:txt_FirstName”, this.NamespaceManager).Value;
string _lastname = main.SelectSingleNode(“/my:myFields/my:txt_LastName”, this.NamespaceManager).Value;
string _mobNum = main.SelectSingleNode(“/my:myFields/my:txt_MobPhone”, this.NamespaceManager).Value;
InsertListItem(_firstname, _lastname, _mobNum); |
- That’s it.
Try to run the code by pressing the green arrow button. When the blank form is displayed, fill in the form and click Submit button.
Since we haven’t implemented any successful / unsuccessful method, then it will not show anything. To find out if you have successfully submitted
the item, please open up the list. You should be seeing the entry. For my scenario it shows:
![]() |
Tomorrow I will show you on how to upload the infopath form to the document library as the InfoPath Form services.




