0

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

kalimuthu
  • 5
  • 1
  • 5

1 Answers1

0

One idea is to make use of the

ContentType.Id.IsChildOf()

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

Verthosa
  • 1,671
  • 1
  • 15
  • 37
  • Thank you for your suggestion, isChildof not available in CSOM Do you have any logics to get shortest GUID from collection? – kalimuthu Sep 12 '16 at 14:39
  • You can get child content types by using a simple 'contains' method. Child content types always contain the id of the parent content type. So by using contains and comparing lengths you could bypass this lack of other methods. Not the best solution but you should be fine – Verthosa Sep 13 '16 at 06:16