Copied to clipboard

Flag this post as spam?

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


  • Tarunjit 103 posts 146 karma points
    Jun 13, 2016 @ 11:32
    Tarunjit
    0

    Get All Unpublished content pages by document type

    Hi All,

    We want to fetch all content pages from umbraco belonging to specific document type.

    For Example :- There are 3 content pages (Page1, Page2 and Page3) and all of these are unpublished and belong to same document type.

    Can any one please let us know the code we need to write fetch complete detail of these pages by applying filter of document type?

    Regards

    Tarunjit Singh

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jun 13, 2016 @ 12:10
    Dennis Adolfi
    1

    Hi Tarunjit!

    Could this work for you?

    @{
        var contentType = ApplicationContext.Services.ContentTypeService.GetContentType("page");
        var unpublishedPages = ApplicationContext.Services.ContentService.GetContentOfContentType(contentType.Id).Where(page => page.Trashed == false && page.Published == false);
    }
    

    Best of luck to you!

    / Dennis

  • Tarunjit 103 posts 146 karma points
    Jun 13, 2016 @ 12:27
    Tarunjit
    0

    Hi Dennis,

    Thanks for the response.

    It worked for me. But suppose out of these pages we want to filter only those pages for which page have particular property value.

    For example Page2 have property "P1" with value "Home" and we want to fetch only that page which have this property with value "Home". In that scenario what will be the condition to be added in above code syntax.

    Regards

    Tarunjit Singh

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jun 13, 2016 @ 12:33
    Dennis Adolfi
    1

    Hi again Tarunjit!

    I dont know what datatype P1 is but try this:

    @{
        var contentType = ApplicationContext.Services.ContentTypeService.GetContentType("page");
        var unpublishedPages = ApplicationContext.Services.ContentService.GetContentOfContentType(contentType.Id).Where(page => page.Trashed == false && page.Published == false).ToList();
        var unpublishedPagesWithP1equalToHome = unpublishedPages.Where(p => p.HasProperty("p1") && p.GetValue("p1").ToString() == "Home");
    }
    
  • Tarunjit 103 posts 146 karma points
    Jun 13, 2016 @ 12:56
    Tarunjit
    1

    Hi Dennis,

    Thanks for the answer.

    How to make sure that from the drop down only string value gets saved in the data base and not the ID value.

    Currently i have noticed that when i fetch value of drop down property its is returning ID value. I am fetching using GetValue("PropertyAlias") Method.

    Regards

    Tarunjit Singh

Please Sign in or register to post replies

Write your reply to:

Draft