Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Zihadul Azam 26 posts 171 karma points c-trib
    Feb 01, 2018 @ 14:29
    Zihadul Azam
    0

    Set ContentType Composition

    Hi,

    I'm trying to create my main Document Types programmatically on ApplicationStarted. Is it possible to set Composition of a ContentType programmatically?

    -Thanks

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Feb 01, 2018 @ 14:37
    Kevin Jump
    100

    Hi

    you need to lookup the other ContentType and add it to a collection of IContentTypeCompositions and then assign this to the ContentTypeComposition value of the parent content type.

    So for example (assuming you have a contentTypeService refrence)

    List<IContentTypeComposition> compositions = new List<IContentTypeComposition>();
    
    var myComp = contentTypeService.GetContentType(compAlias);
    compositions.Add(myComp);
    
    myContentType.ContentTypeComposition = compositions;
    
    contentTypeService.Save(myContentType);
    

    you can see this (and a bit more) in the uSync source - as it does this on import of content types from disk.

Please Sign in or register to post replies

Write your reply to:

Draft