sharepoint-2013csomevent-receiver

What is best method to get property for the content type with the closest match using client context (CSOM)?


I’m converting Event receiver codes into Remote event receiver using SharePoint 2013 Client context.

var documentList = clientContext.Web.GetList(Constants.DocumentsListUrl);
var classifiedContentTypeId = documentList.ContentTypes.BestMatch(new
SPContentTypeId("0x0120D52000155C54BB8DF04DE78D5F78461B236DEF"));
var classifiedContentType =  
documentList.ContentTypes[classifiedContentTypeId];

Note that if the search finds two matches, the shorter ID is returned. For example, if 0x0101 is the argument, and the collection contains both 0x010109 and 0x01010901, the method returns 0x010109.

List.ContentTypes.BestMatch method is available to get closest match in SSOM. What is the right method in CSOM ? Thanks in advance


Solution

  • One idea is to make use of the

    ContentType.Id.IsChildOf()
    

    method and then use string methods to choose the shortest Guid ?