0

I have site content type available in my SP 2013 site, I need Content Type ID by content type name using CSOM.

I found the way by using rest api from here Get Site Content Type ID by Content Type Name using REST API

But i am restricted to use CSOM.

Any help will be appreciated.

1 Answer 1

0

If using C# CSOM you can try something like this ContentTypeCollection Extension

// taken from link above!!!
public static class ContentTypeExtensions
{
    public static ContentType GetByName(this ContentTypeCollection cts, string name)
    {
        var ctx = cts.Context;
        ctx.Load(cts);
        ctx.ExecuteQuery();
        return Enumerable.FirstOrDefault(cts, ct => ct.Name == name);
    }
}

Once you return the content type by name using the extension method, you should be able to pull the ID off of the variable.

var siteCT = ctx.Site.RootWeb.ContentTypes.GetByName("<Name>");

var CTID = siteCT.Id;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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