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.


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);
return listItem;