Copied to clipboard

Flag this post as spam?

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

  • Janet Kirklen 102 posts 212 karma points
    Sep 08, 2014 @ 22:42
    Janet Kirklen

    Get Document Type Name

    As part of a search filter I need to build a drop down list of document types.   I can get the nodeTypeAlias easily, but how can I get the Name of the docType for a given nodeTypeAlias?   Is there a library or namespace that exposes that?

  • Dennis Aaen 4497 posts 18205 karma points admin hq c-trib
    Sep 08, 2014 @ 23:18
    Dennis Aaen

    Hi Janet,

    Frist of all I am not a .NET developer, but I work as a frontend developer, so normally I work with Razor and XSLT, HTML, CSS and so on. But I will try to help you the best I can.

    I found some documentation about documents, that I think could be interesting for you maybe. By using the .ContentType you should get the retuns of a .ContentType object representing the DocumentType used by the given Document.

    The first link if for Umbraco version 6+ and use the ContentTypeService: There is a method called .GetContentType()

    I hope this can help you.


  • Janet Kirklen 102 posts 212 karma points
    Sep 09, 2014 @ 00:30
    Janet Kirklen

    Thanks Dennis.  You pointed me in the general direction.  For Umbraco 6.x and7 it looks like the Document class has been replaced with the Content Class.  This link gave the equivalent info.


    using Umbraco.Core.Services;
    var content = Services.ContentService.GetById(sr.Id);
    var docName = content.ContentType.Name;
    That got me to the name of the doc type.
  • Harvey 28 posts 122 karma points
    Nov 07, 2016 @ 11:19

    As a note, I wouldn't recommend using the ContentService too much as it gets node data straight from the database which is far slower than getting it from the content cache (which is accessed using the UmbracoHelper).

    You can also get the document/content type from the database this way:

    var services = UmbracoContext.Application.Services;    
    var documentType = services .ContentTypeService.GetContentType(Model.Content.DocumentTypeId);
    var docName = documentType.Name;

    This method may not be faster than the one provided by Janet as it also gets data from the database, but it's likely that the document/content type table is smaller so theoretically it should be faster.

Please Sign in or register to post replies

Write your reply to: