how to get all documents (pages) of same page type?

Muhammad Kaleem asked on April 26, 2019 17:50

this is structure of my pages structure on application...

level 1......(pagetype abc)

-level 2.......(pagetype bcd)

--level 3........(pagetype cde)

level 1......(pagetype abc)

-level 2.......(pagetype bcd)

--level 3........(pagetype cde)

i want to get all the pages (documents) of third level having same page type i.e. cde, if anyone knows about please help...

thanks

Correct Answer

Zach Perry answered on April 26, 2019 18:58

You can do something like this:

var selparams = new NodeSelectionParameters
            {
                ClassNames = "Custom.Page",
                Where = "NodeLevel = 3",
                SelectOnlyPublished = true
            };
            DocumentHelper.GetDocuments(selparams, new TreeProvider()).Items.ToList();

Another option is to create a class from your page type using the generated code in the CMS, and do something like this:

var pages = CustomPageTypeProvider.GetCustomPageType().Published().Where("Nodelevel", QueryOperator.Equals, 3)

You can find other ways by looking into the document query documentation

1 votesVote for this answer Unmark Correct answer

Recent Answers


Muhammad Kaleem answered on April 26, 2019 19:26 (last edited on April 26, 2019 19:29)

thanks Zach Perry, i'm getting pages in this way

 IEnumerable<TreeNode> lstnews =
  DocumentHelper.GetDocuments("CMS.News").OnCurrentSite().Published().TopN(1).ToList();

but, unable to get image, can you please suggest...

if (item.GetValue("ThumbnailImage") != null && item.GetValue("ThumbnailImage").ToString() != "") { strCountryImage = item.GetValue("ThumbnailImage").GetPath(); }

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.