2

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(); 
}
Kurkula
  • 6,386
  • 27
  • 127
  • 202

2 Answers2

3

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();
}
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • This property is an email id. Can we use this folder property to use for share point notification? – Kurkula Mar 12 '15 at 01:01
  • 1
    A query - Normally the Folder content type is sealed by Microsoft. I am wondering if you have these email columns available to edit when you are using the browser ? – Godwin Mar 13 '15 at 14:15
  • This will work only on Sharepoint 2013+ on 2010 ListItemAllFields is not exposed for folders. – Brlja Feb 26 '16 at 10:01
  • This does not work for 2010. What changes I need to make in order to work with 2010? – Aakash Maurya Aug 02 '16 at 13:56
1

Here is the code that will update only the items of one folder

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

                List list = ctx.Web.Lists.GetByTitle("User Details");
         CamlQuery spQuery = CamlQuery.CreateAllItemsQuery();
                spQuery.FolderServerRelativeUrl = "Enter Relative URL TO FOLDER"  // Example "/managedpath/site/Lists/listname/Folder Name"
                Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(spQuery);
                ctx.Load(items); 
                ctx.ExecuteQuery();

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

Please mark as answer , if this works for you.

Godwin
  • 600
  • 5
  • 16