Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

search based on Tree level or based on URL



i have a site with pages like this structure.



  • c
  • d
  • e


  • g
  • h
  • i

suppose if am browsing c page and i click serch button, then i want to display serch results under b level tree.dont want to display f tree level results.

suppose if am browsing g page and i click serch button, then i want to display serch results under f level tree.dont want to display b tree level results.


otehrwise is there any option to filter GetResult() after search hits.

Edited, Aug 17, 2020 10:17

When performing the search, you just need to locate what part of the tree structure you are inside, and filter the Ancestors-list by that:

.Filter(x => x.Ancestors().Match(a-b-or-f-page.ContentLink.ToReferenceWithoutVersion().ToString())

If a, b and f are landing pages of the same page type, you could do simething like this:

public static T GetParentOfType<T>(this ContentReference contentReference) where T : PageData
	if (contentReference.IsNullOrEmpty())
		return null;

	while (contentReference != ContentReference.EmptyReference)
		var content = contentReference.Get<PageData>();
		if (content is T)
			return content as T;

		if (contentReference.Equals(ContentReference.StartPage))
			return null;

		if (content == null)
			return null;

		contentReference = content.ParentLink;

	return null;

And then:

.Filter(x => x.Ancestors().Match(currentPage.GetParentOfType<MyLandingPage>().ContentLink.ToReferenceWithoutVersion().ToString())
Edited, Aug 17, 2020 12:30

Hi Tomas.

Thanks for your reply.

am getting below error.

the Ancestorsdoes not exist in the current context.

Aug 19, 2020 10:05
Tomas Hensrud Gulla - Aug 19, 2020 10:23
Could you post your complete query?

Ancestors() is an extensions method defined in the namespace EPiServer.Find.Cms.ContentExtensions

What version of Find are you using?

Edited, Aug 19, 2020 19:04
* 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.