Search code examples
c#sharepointsharepoint-clientobject

Sharepoint Client Object Model Updating Property of a only one folder


I am working on a sharepoint clientobjectmodel code. There is a folder called "John Details" inside "User Details Folder". I am trying to update 2 properties for the "John Details" folder. How do I do that?

Public Void UpdateColumnsForOnlyOneFolder(maildId1,mailId2){
               ClientContext ctx = new ClientContext("http://mytestsite/");

                List list = ctx.Web.Lists.GetByTitle("User Details");
                Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery());
                ctx.Load(items); 
                ctx.ExecuteQuery();

                foreach (var item in items)
                {
                    item["email1"] = mailId1;              
                    item["email2"] = mailId2;              
                    item.Update();
                }
                ctx.ExecuteQuery(); 
}

Solution

  • If I understood your question properly, you would like to update the folder's associated list item properties. If so, you could consider the following approach:

    Example

    using (var ctx =  new ClientContext(webUri))
    {
       var web = ctx.Web;
    
       var folder = web.GetFolderByServerRelativeUrl("/site/Documents/folder/sub folder");
       var listItem = folder.ListItemAllFields;
       listItem["PropertyName"] = "PropertyValue";
       listItem.Update();
       ctx.ExecuteQuery();
    }