manoj´ssharepointblog

SharePoint Blog


Leave a comment

How to programmatically Create SPListItem in a SPFolder

Sample Code to Create SPListItem in a SPFolder

SPSite mySite = new SPSite(http://ServerName/sitename);
SPWeb web = mySite.OpenWeb();
SPList list = web.Lists[“ListName”];
SPFolder f = web.GetFolder(http://ServerName/sitename/Lists/ListName/FolderName);
if(f.Exists)
{
SPListItemCollection itemColl = list.Items;
SPListItem item = itemColl.Add(f.ServerRelativeUrl , SPFileSystemObjectType.File, null);
item[“Title”] = “Added from Code”;
item.Update();
}