Share via


Creating a SPListItem in a SPFolder

SPSite site = new SPSite("https://[ServerName/sitename]");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["ListName"];

SPFolder f = web.GetFolder("https://[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();
}

https://suguk.org/blogs/tomp/archive/2006/09/28/Adding_SPListItems.aspx

Comments

  • Anonymous
    May 30, 2010
    Good One