Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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);
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!
I guess this will help
var cts = ApplicationContext.Current.Services.ContentTypeService;ContentType ct =(ContentType)cts.GetContentType(123456);
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted