1

How to manage the metadata of document sets using C#+CSOM. Any sample code is appreciated. below is the code i tried for creating the document set.

       ....
         .....
     ContentType targetDocumentSetContentType = result.FirstOrDefault();
     ListItemCreationInformation newItemInfo = new 
     ListItemCreationInformation();
    newItemInfo.UnderlyingObjectType = 
       FileSystemObjectType.Folder;
     newItemInfo.LeafName = "Document Set1";
  //newItemInfo.FolderUrl = list.RootFolder.ServerRelativeUrl.ToString();
   ListItem newListItem = list.AddItem(newItemInfo);
     newListItem["ContentTypeId"] = 
       targetDocumentSetContentType.Id.ToString();
        newListItem.Update();
        list.Update();
       clientContext.ExecuteQuery();

the above code for creation of document set, but i am stuck at how to modify the properties.

0

The following C# with CSOM code for your reference.

var siteUrl = "http://sp2013";
var username = "username";
var password = "password";
var domain = "domain";
string documentLibraryName = "DocumentLibrary";
string documentSetName = "DdocumentSet1";
string propertyName = "field1";
string updatePropertyValue = "LZ";

using (ClientContext ctx = new ClientContext(siteUrl))
{
    ctx.Credentials = new NetworkCredential(username, password, domain);
    Web site = ctx.Web;
    List docLib = site.Lists.GetByTitle(documentLibraryName);
    ctx.Load(docLib);
    CamlQuery caml = new CamlQuery();
    caml.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='text'>"+documentSetName+"</Value></Eq></Where></Query></View>"; ;
    ListItemCollection items = docLib.GetItems(caml);             
    ctx.Load(items);
    ctx.ExecuteQuery();
    if (items.Count != 0)
    {
        ListItem item = items[0];
        var properties = item.Folder.Properties;
        properties[propertyName] = updatePropertyValue;
        item.Folder.Update();
        ctx.ExecuteQuery();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.