Class Category
Read and edit category information
Inheritance
Implements
Inherited Members
Namespace: EPiServer.DataAbstraction
Assembly: EPiServer.dll
Version: 7.19.2Syntax
public class Category : ICloneable, IListSource
Remarks
Categories are hierarchical data so every Category class has a collection of child categories. There are support functions to help finding child categories both by name or by ID on all categories, see examples below.
Category implements IListSource which mean you can take any category class and databind it to enumerate all child categories in a recursive manner using for example datagrid filtering.
Examples
Example that demonstrates searching for a category with name "Data" and then demonstrates that you can search for a category in another category's children. The Find method always searches recursivly in all children.
Example that demonstrates how to create a new category and then deleting a category.
Iterate all categories
Constructors
Category()
Initializes a new instance of the Category class.
Declaration
public Category()
Category(String, String)
Initializes a new instance of the Category class.
Declaration
public Category(string name, string description)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the category. |
System.String | description | A description of the category. |
Fields
RootName
Name of the root category.
Declaration
public const string RootName = "Root"
Field Value
Type | Description |
---|---|
System.String |
Properties
Available
If the category should be available in edit mode
Declaration
public bool Available { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Categories
Child categories
Declaration
public CategoryCollection Categories { get; set; }
Property Value
Type | Description |
---|---|
CategoryCollection |
Description
Description of category
Declaration
public string Description { get; set; }
Property Value
Type | Description |
---|---|
System.String |
GUID
Globally unique identifier
Declaration
public Guid GUID { get; set; }
Property Value
Type | Description |
---|---|
System.Guid |
ID
The database unique identification number
Declaration
public int ID { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Indent
The indent where the root category is 0
Declaration
public int Indent { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
LocalizationService
Declaration
public LocalizationService LocalizationService { get; set; }
Property Value
Type | Description |
---|---|
LocalizationService |
LocalizedDescription
Localized description of category, will fall back to Description if not found.
Declaration
public string LocalizedDescription { get; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The description field is html encoded if used.
Name
Name of category
Declaration
public string Name { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Parent
Parent category or null for the root category
Declaration
public Category Parent { get; set; }
Property Value
Type | Description |
---|---|
Category |
Selectable
If the category should be selectable in edit mode
Declaration
public bool Selectable { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
SortOrder
The index for sorting categories on the same branch
Declaration
public int SortOrder { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
Clone()
Clone this category and all children to get a new instance
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.Object | A new identical category derived from the current |
Delete()
Delete the current category and its children from the collection and database
Declaration
public void Delete()
Find(Int32)
Recursive search for a category starting at the root
Declaration
public static Category Find(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | The id number for the category to find |
Returns
Type | Description |
---|---|
Category | The found category or null of the category could not be found |
Find(String)
Recursive search for a category starting at the root
Declaration
public static Category Find(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name number for the category to find |
Returns
Type | Description |
---|---|
Category | The found category or null of the category could not be found |
FindChild(Int32)
Recursive search for a category in all descendant children
Declaration
public Category FindChild(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | The id number for the category to find |
Returns
Type | Description |
---|---|
Category | The found category or null of the category could not be found |
FindChild(String)
Recursive search for a category in all descendant children
Declaration
public Category FindChild(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name number for the category to find |
Returns
Type | Description |
---|---|
Category | The found category or null of the category could not be found |
GetList()
Return all descendant categories. Implements IListSource which provides the functionality so a category tree can be databound as a flat list.
Declaration
public IList GetList()
Returns
Type | Description |
---|---|
System.Collections.IList |
GetRoot()
Get the category tree starting at the root
Declaration
public static Category GetRoot()
Returns
Type | Description |
---|---|
Category | The root category |
Save()
Save changes made to the current category
Declaration
public void Save()
Remarks
Will only save changes to the current category and not child categories