Content Type Service
Examples on how to retrieve content types and content type containers using the ContentTypeService.
Learn how to work with Content Types through the Content Type Service.
Getting a single content type
A given content type has a few different unique identifier that we can use to look it up via the content type service. For instance, if we know the GUID of the content type, we can look it up like this:
Although the use of a GUID is preferable, you can also use it's numeric ID:
Finally, you can also look up a content type by its alias:
Getting a list of content types
As content types are stored in a hierarchical list with folders (containers), there is also multiple ways to can get content types. If you are looking for a flat list of all content types, you can use the GetAll
method:
In the example above, the method was called without any parameters. The method also has two overloads, which lets you look up a collection fo content types by either specifying their GUID or numeric IDs:
To get a list of all Content Types of another content type, you can use the GetChildren
method. This can be done by specifying the numeric ID or the GUID:
Check whether a content type has children
In some cases it can be useful to check if a content type has children. The HasChildren
method can be used to check whether a content type has children.
Although the use of a GUID is preferable, you can also use it's numeric ID:
Retrieving content type container
Getting a single content type container
You can add content types in three different ways. At the root level, under another content type, or under a container (which is a folder). To obtain a single container, the process is similar to obtaining a single content type. This means that you can search for a container either by its GUID:
or its numeric counterpart:
Getting a list of content type containers
In the same way as you can get the content types of a container, you can get the child containers of another container. This is done by calling the GetContainers
method with an array of numeric IDs:
Also, if the array is empty, all containers will be returned:
Last updated