Add An Item To A Folder To A List With CSOM

Its really similar to how you would do it with traditional server side OM means. This is a static helper method that will generate a new folder in some list. Essentially we just have to spin a ListItemCreationInformation object specified with empty properties and just set the FolderUrl.

[csharp]

public static ListItem AddItemInFolder(string siteUrl, string listName, string folderPath, ClientContext clientContext)
{
List list = clientContext.Web.Lists.GetByTitle(listName);
ListItemCreationInformation listItemCreationInformation = null;
if (!String.IsNullOrEmpty(folderPath))
{
listItemCreationInformation = new ListItemCreationInformation();
listItemCreationInformation.FolderUrl = String.Format(“{0}/{1}”, siteUrl, folderPath);
}
ListItem listItem = list.AddItem(listItemCreationInformation);
listItem.Update();
clientContext.ExecuteQuery();
return listItem;
}

[/csharp]

Share

No Comments

Trackbacks/Pingbacks

  1. Add An Item To A Folder To A List With CSOM - SharePoint MVP Blogs - Bamboo Nation - [...] Its really similar to how you would do it with traditional server side OM means. This is a static…

Leave a Reply

Your email address will not be published. Required fields are marked *