Create Sharepoint List items using Infopath 2010

To develop code using the SharePoint object model, you need to add a reference to Microsoft.SharePoint.dll to your VSTA project. This DLL is installed in %CommonProgramFiles%\Microsoft Shared\Web Server Extensions\14\ISAPI with your licensed copy of Microsoft SharePoint Server.

Below is the Code to add Category Name in the Category list in SharePoint.

public void Category_Changed(object sender, XmlEventArgs e)

using (SPSite FormSite = new SPSite(ServerInfo.SharePointSiteUrl.ToString()))

using (SPWeb FormWeb = FormSite.OpenWeb())

//Get the list
SPList CatList = FormWeb.Lists["Category"];

//I have changed the name of Title Column to Category in the list.
So, /my:myFields/my:Category is the xpath to the Category field and internal name would be "Title".

//Add an item to the Category list
SPListItem NewItem = CatList.Items.Add();

NewItem["Title"] = GetDomValue("/my:myFields/my:Category");

//Set AllowUnsafeUpdates = true to update the database

FormWeb.AllowUnsafeUpdates = true;


FormWeb.AllowUnsafeUpdates = false;
} }}

private string GetDomValue(string XpathToGet)
return this.CreateNavigator().SelectSingleNode(XpathToGet, this.NamespaceManager).Value; }


Post a Comment


This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at .

Copyright (c) 2010 @ All rights are reserved.Do Not Copy.

@ Learning