Copied to clipboard

Flag this post as spam?

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


  • Shahid Abdullah 6 posts 76 karma points
    Sep 07, 2016 @ 07:59
    Shahid Abdullah
    0

    Get properties of a Blog Post

    I have Blog Repository and it contains blog posts list. I am accessing all Blog Posts by using this code

    var contentType = ApplicationContext.Services.ContentTypeService.GetContentType("BlogPost");
    
    var blogPostList = ApplicationContext.Services.ContentService.GetContentOfContentType(contentType.Id);
    

    Now I am accessing custom data type properties by using

    foreach (var blog in blogPostList)
        {
    
            foreach ( var property in blog.Properties)
            {
    
            }
    
        }
    

    Now I can access properties and get its value but for few properties I get json String and that is no use for me as I would need to create models to properly parse json string into proper json.

    Is there any way to use GetPropertyValue in this situation or some other way to get properly formatted Json.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Sep 07, 2016 @ 10:32
    Dave Woestenborghs
    1

    Hi Shahid,

    Are you using this code to display your blogpost on your website ?

    If yes, this code will cause you performance problems real quickly, because ApplicationContext.Services.ContentService and ApplicationContext.Services.ContentTypeService hit the database and are not cached. It will also show deleted and unpublished content.

    If it's for display purposes you need to use the IPublishedContent interface (see https://our.umbraco.org/documentation/Reference/Querying/IPublishedContent/)

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft