How to add item to list subfolder using Client object model
protected void AddItemInFolder(object sender, EventArgs e) { string siteURL = SPContext.Current.Web.Url; AddItemInFolders(siteURL, "Docs", "Folder1/Folder2");//subfolders AddItemInFolders(siteURL, "Docs", "Folder1");//root folder } private void AddItemInFolders(string siteUrl, string listName, string folderPath) { using (var clientContext = new ClientContext(siteUrl)) { var list = clientContext.Web.Lists.GetByTitle("Docs"); ListItemCreationInformation listItemCreationInformation = null; if (!string.IsNullOrEmpty(folderPath)) { listItemCreationInformation = new ListItemCreationInformation();
listItemCreationInformation.LeafName = folderName; listItemCreationInformation.UnderlyingObjectType = FileSystemObjectType.Folder;
listItemCreationInformation.FolderUrl = string.Format("{0}/lists/{1}/{2}", siteUrl, listName, folderPath); } var listItem = list.AddItem(listItemCreationInformation); listItem["Title"] = "Titile1"; listItem.Update(); clientContext.ExecuteQuery(); } }
댓글 없음:
댓글 쓰기