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
    0

    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 4499 posts 18254 karma points admin hq c-trib
    Sep 08, 2014 @ 23:18
    Dennis Aaen
    0

    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()

    http://our.umbraco.org/documentation/reference/Management-v6/Services/ContentTypeService#GetContentType%28stringalias%29

    http://our.umbraco.org/documentation/Reference/management/Documents/document#ContentType

    I hope this can help you.

    /Dennis

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

    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.  

    http://our.umbraco.org/documentation/Reference/Management-v6/Models/Content

     

    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
    Harvey
    1

    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:

Draft