Please tell me there's a better way to do this than;
public PageDataCollection findPagesWithFilename(PageReference pageLink, string filename)
{
PageDataCollection pages = new PageDataCollection();
foreach(PageData pd in Global.EPDataFactory.GetChildren(pageLink))
{
string temp = EPiServer.DataAbstraction.PageType.Load(pd.PageTypeID).FileName;
if(temp.Substring(temp.LastIndexOf("/")+1) == filename)
pages.Add(pd);
pages.Add(findPagesWithFilename(pd.PageLink,filename));
}
return pages;
}
The code is ok for small amounts of pages and non recursive searches. But, you already know the filename you're searching for, why not map that to the pagetype by iterating through the PageType collection and look for it. When you know the pagetype, you can do a property search (FindPagesByCriteria(...)) with the PageTypeID as a search parameter. This should give you better performance if you're searching through a lot of pages.
/Steve
public PageDataCollection findPagesWithFilename(PageReference pageLink, string filename) { PageDataCollection pages = new PageDataCollection(); foreach(PageData pd in Global.EPDataFactory.GetChildren(pageLink)) { string temp = EPiServer.DataAbstraction.PageType.Load(pd.PageTypeID).FileName; if(temp.Substring(temp.LastIndexOf("/")+1) == filename) pages.Add(pd); pages.Add(findPagesWithFilename(pd.PageLink,filename)); } return pages; }