Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

GetDescendents on the basis of pageName

Vote:
 

How to get Descent pages on basis of parent Page Name

#45753
Nov 16, 2010 13:48
Vote:
 

I'm just going to take a guess on what you want --

To get a page by PageName, you'll need to do a FindPagesByCriteria search for it.  This isn't ideal, as PageName is not unique, so make sure you have the one you want.

Once you get that page, do this to get its children:

 

PageDataCollection childPages = DataFactory.Instance.GetChildren(parentPage.PageLink);
    
#45754
Edited, Nov 16, 2010 13:55
Vote:
 

Thanks for the reply.what is the value of parentPage.PageLink ?

#45758
Nov 16, 2010 14:31
Vote:
 

When you run FindPagesWithCriteria it returns a PageDataCollection. The parentPage in Deane's example is one of the pages in that collection, the one you consider to be the match. The FindPages call could look something like this

var pageNameToFind = "Test";
var matches = DataFactory.Instance.FindPagesWithCriteria(
    PageReference.StartPage,
    new PropertyCriteriaCollection()
    {
        new PropertyCriteria()
        {
            Condition = EPiServer.Filters.CompareCondition.Equal,
            Name = "PageName",
            Required = true,
            Type = PropertyDataType.String,
            Value = pageNameToFind
        }
    });

#45759
Nov 16, 2010 15:20
Vote:
 

Hi,

Thanks for the reply. Can we search the page  if we have only PageTypes. like With this creteria I got all the subpage under ther page name "Test" and I want page  having pagetype "test Contact" .

#45789
Nov 17, 2010 10:14
Vote:
 

You could add a criteria to search for pages of a particular pagetype.

#45790
Nov 17, 2010 10:31
Vote:
 

Hi,
Thanks for the reply.
In the above patch of code given by Magnus if i want to get childrens.

 PageDataCollection childPages = DataFactory.Instance.GetChildren(matches.PageLink);
 
 Is this is the right way. what should be "matches.PageLink" ???

#45800
Nov 18, 2010 6:08
Vote:
 

matches is going to be a PageDataCollection.  Remember that PageName isn't unique, so you could get back one page or a hundred.

matches is a collection of PageData objects, so to get the children of the first one:

PageDataCollection childPages = DataFactory.Instance.GetChildren(matches[0].PageLink);
    
#45801
Nov 18, 2010 6:11
Vote:
 

Hi,
Thanks for the reply and if i want page among all the childrens having pagetype "contact" .
then I am adding again cretaria in all the subpages.

var contact = DataFactory.Instance.FindPagesWithCriteria(
                PageReference.StartPage,
                new PropertyCriteriaCollection()
            {
                new PropertyCriteria()
                {
                    Condition = EPiServer.Filters.CompareCondition.Equal,
                    Name = "PageTypeValue",
                    Required = true,
                    Type = PropertyDataType.String,
                    Value = contact
                }
            });
   
in that case whaqt should be the PageReference.StartPage , childPages??

#45802
Nov 18, 2010 6:38
Vote:
 

You can use multiple criteria in the same query, like so:

var pageNameToFind = "Test";
var pageTypeIdToFind = 2;
var matches = DataFactory.Instance.FindPagesWithCriteria(
    PageReference.StartPage,
    new PropertyCriteriaCollection()
    {
        new PropertyCriteria()
        {
            Condition = EPiServer.Filters.CompareCondition.Equal,
            Name = "PageName",
            Required = true,
            Type = PropertyDataType.String,
            Value = pageNameToFind
        },
        new PropertyCriteria()
        {
            Condition = EPiServer.Filters.CompareCondition.Equal,
            Name = "PageTypeID",
            Required = true,
            Type = PropertyDataType.PageType,
            Value = pageTypeIdToFind.ToString()
        }
 
    });

PageReference.StartPage in the FindPagesWithCriteria call indicates where in the pagetree to start the search.

You can find most of this information at http://sdk.episerver.com (both class reference and useful howtos in the developers guide section) and the documents section here at World: http://world.episerver.com/Documentation/

#45803
Nov 18, 2010 6:45
Vote:
 

Hi,
Thanks for the reply .I want two property one from Page A and other from the one of children of A
I am doing loop that is:

 foreach (PageData startPage in DataFactory.Instance.GetChildren(matches[0].PageLink))
            {
                if (startPage.PageTypeName == "contact")
    {
    
    }
 Can I get the properties of the page having startPage.PageTypeName == "contact"? 

#45804
Nov 18, 2010 7:19
Vote:
 

Ah, I misunderstood. If you want to find something in the direct children of the page, looping through them like you do is probably better than doing a second FindPages... unless there are many child pages. So your loop should find the child pages with page type named "contact", and you can then just read properties from that page (startPage["MainBody"] etc.).

#45806
Nov 18, 2010 7:32
Vote:
 

Hi,

 thanks for the reply. just like startPage["mainBody"] can we retrieve the values from matches[0], the page we get from serchbycreteria.?

#45808
Nov 18, 2010 7:40
Vote:
 

Of course, they're all PageDatas. Intellisense should help you see that and what else you can do and not.

#45809
Nov 18, 2010 7:41
Vote:
 

Intellisense and a check in the sdk should help: 

http://webhelp.episerver.com/

#45811
Nov 18, 2010 9:10
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.