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();
}


Comments

Popular posts from this blog

Adding Contact Selector Control to InfoPath form

Adding Validation to a Custom NewForm.aspx in SharePoint & Redirect

How to add to Sub-Sub Menu in SharePoint