Copied to clipboard

Flag this post as spam?

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

  • Joao Pinto 24 posts 64 karma points
    Feb 19, 2013 @ 18:01
    Joao Pinto

    umbraco v6 - get content type by ID, easier way?


    I need to get a ContentType object by ID, on umbraco v4 I used to do it using the DocumentType object, it was pretty easy, looks like with ContentType now it's really a mess, but maybe I'm just doing it the wrong way?

    Basically I needed to create 4(!!!) objects just to be able to use the method GetContentType, it would be much easier to just have a static method...

    Anyone know a better way to do it? Below my code.


    //get content type.. a lot of stuff... any way to do it faster/better?
    ContentService cs = new ContentService();
    RepositoryFactory rf = new RepositoryFactory();
    MediaService ms = new MediaService(rf);
    ContentTypeService cts = new ContentTypeService(cs, ms);
    ContentType ct = (ContentType)cts.GetContentType(123456);
  • Sébastien Richer 194 posts 430 karma points
    Jun 18, 2013 @ 20:40
    S├ębastien Richer

    I just ran into this exact problem on my search page. I wanted to display the document type's name on the website. Not the sexiest code, but thanks Joao, this helped me!

  • Roman Khanenko 1 post 22 karma points
    Sep 06, 2013 @ 09:23
    Roman Khanenko

    I guess this will help

    var cts = ApplicationContext.Current.Services.ContentTypeService;
    ContentType ct =(ContentType)cts.GetContentType(123456);


Please Sign in or register to post replies

Write your reply to: