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

Try our conversational search powered by Generative AI!

Determine whether a certain category is set for a page

Vote:
 

Hello

I want to check to see whether a certain category exists for a page. I have pagedata and from that i can access category, right?

But how do i loop through the categories for that page to see if anyone matches the category i look for?

 

Example

I'm looking for a category called "fish" now i have page A and want to find out if page A has the category fish added to it.

 

/Jonas

#50468
May 03, 2011 13:00
Vote:
 
 
Hi,
Try this (page is a PageData object)
var category = Category.Find("fish");
if (category != null)
{
  bool isOfCat = page.Category.MemberOf(category.ID);
}
 
/Michel
#50480
Edited, May 03, 2011 14:38
Vote:
 

Hi

 

Thanks, worked perfectly!

If any one else should find this useful:
Just remember to add a reference to EpiServer.DataAbstraction namespace   :-)

/Jonas

#50484
May 03, 2011 16:18
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.