Details of CRUD operations within Umbraco and how to interact with the data persisted in the database
The intended audience for these reference pages is .NET developers. It is assumed the reader already knows the basics of Umbraco and knows .NET & C#.
Since the release of Umbraco 14, the documentation for Models and Services has been removed from the documentation.
Find references for the models in the public API. The models include Content, ContentType, Language, Media, and Template classes.
Find references for the services available for performing Create, Read, Update, and Delete (CRUD) operations for the models.
Find a handful of resources for using some of the services available with Umbraco CMS.
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.
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:
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:
The service also have GetMany
-methods to get a collection of content types by their GUIDs IDs 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:
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:
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:
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:
List of service references along with instructions on how to use them, as well as some examples for better understanding.
In this article you can learn how to use and work with some of the services provided with Umbraco CMS.
You can find a list of all supported services in the API Documentation.
All services can be accessed with the following using statement:
In some cases, you can use Dependency Injection. For example, if you have registered your class in Umbraco's dependency injection, you can specify the service interface in your constructor.
To use the NotificationService
you can use Dependency Injection via the INotificationService
interface like this:
In Razor views, you can access the Notification Service through the @inject
directive:
Use the above example for other services by replacing the interface and the name of the service.