Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The EntityService acts as a "gateway" to Umbraco data for operations which are related to entities.
Browse the API documentation for IEntityService interface.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the entity service in a class, you need to specify the IEntityService
interface in your constructor:
In Razor views, you can access the entity service through the @inject
directive:
Applies to Umbraco 9 and newer
Browse the API documentation for ConsentService.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
A service for handling lawful data processing requirements.
A consent is fully identified by a source (whoever is consenting), a context (for example, an application), and an action (whatever is consented). A consent state registers the state of the consent (granted, revoked...).
Consent can be given or revoked or changed via the RegisterConsent
method, which creates a new Consent
entity to track the consent.
Getter methods of this service return the current state of a consent, that is the latest IConsent entity that was created.
Revoking a consent is performed by registering a revoked consent.
A consent cannot be deleted. It can only be revoked by registering a "revoked consent".
In Razor views, you can access the consent service through the @inject
directive:
The AuditService acts as a "gateway" to Umbraco data for operations which are related to the audit trail.
Browse the API documentation for IAuditService interface.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the audit service in a class, you need to use Dependency Injection (DI). For instance if you have registered your own class in Umbraco's DI container, you can specify the IAuditService
interface in your constructor:
In Razor views, you can access the audit service through the @inject
directive:
The DataTypeService acts as a "gateway" to Umbraco data for operations which are related to DataTypes and DataTypeDefinitions.
Browse the API documentation for IDataTypeService.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the Data Type service in a class, you need to specify the IDataTypeService
interface in your constructor:
In Razor views, you can access the Data Type service through the @inject
directive:
Defines the MacroService, which is an access to operations involving IMacro
.
Browse the API documentation for IMacroService interface.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
For Razor views:
If you wish to use the macro service in a class, you need to specify the IMacroService
interface in your constructor:
In Razor views, you can access the macro service through the @inject
directive:
The MemberService acts as a "gateway" to Umbraco data for operations which are related to Members.
Browse the API documentation for IMemberService interface.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the member service in a class, you need to specify the IMemberService
interface in your constructor:
In Razor views, you can access the member service through the @inject
directive:
The DomainService acts as a "gateway" to Umbraco data for operations which are related to domains.
Browse the API documentation for IDomainService.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the domain service in a class, you need to specify the IDomainService
interface in your constructor:
In Razor views, you can access the domain service through the @inject
directive:
The FileService acts as a "gateway" to Umbraco data for operations which are related to Scripts, Stylesheets and Templates.
Browse the API documentation for IFileService.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the file service in a class, you need to specify the IFileService
interface in your constructor:
In Razor views, you can access the file service through the @inject
directive:
The PackagingService provides import/export functionality for the Core models of the API.
Browse the API documentation for IPackagingService interface.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
In other cases, you may be able to use Dependency Injection. For instance if you have registered your own class in Umbraco's dependency injection, you can specify the IPackagingService
interface in your constructor:
In Razor views, you can access the member service through the @inject
directive:
The NotificationServices is used to perform operations related to backoffice notifications.
Browse the API documentation for INotificationService interface.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
In other cases, you may be able to use Dependency Injection. For instance if you have registered your own class in Umbraco's dependency injection, you can specify the INotificationService
interface in your constructor:
In Razor views, you can access the member type service through the @inject
directive:
The RedirectUrlService is used for CRUD operations related to Redirects.
.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
In other cases, you may be able to use Dependency Injection. For instance if you have registered your own class in Umbraco's dependency injection, you can specify the IRedirectUrlService
interface in your constructor:
In Razor views, you can access the member service through the @inject
directive:
Service to handle public access.
.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
In other cases, you may be able to use Dependency Injection. For instance if you have registered your own class in Umbraco's dependency injection, you can specify the IPublicAccessService
interface in your constructor:
In Razor views, you can access the member service through the @inject
directive:
The ExternalLoginService is used to store the external login info and can be replaced with your own implementation.
.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
If you wish to use the entity service in a class, you need to specify the IExternalLoginService
interface in your constructor:
In Razor views, you can access the entity service through the @inject
directive:
The MediaService acts as a "gateway" to Umbraco data for operations which are related to media.
.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require reference to the following packages:
Samples in this document will require the following using statements:
If you wish to use the media service in a class, you need to specify the IMediaService
interface in your constructor:
In Razor views, you can access the media service through the @inject
directive:
To create a new folder at the root of the media archive, your code could look like the following:
Alternatively, you can replace the Constants in the above sample with hardcoded values.
For the CreateMedia
method, the first parameter is the name of the folder to be created.
The second parameter is the ID of the parent media item. Constants.System.Root
is a constant defined in Umbraco with the value of -1
, which is used for indicating the root of the media archive. Instead of specifying the numeric ID of the parent, you may instead specify either a Guid
ID or an IMedia
instance representing the parent media.
The third parameter is the alias of the Media Type. As Umbraco comes with a Folder Type by default, we can use the Constants.Conventions.MediaTypes.Folder
constant to specify that the alias of the Media Type is Folder
.
Besides the three mandatory parameters, you can specify a user's numeric ID for media creation attribution. Unspecified cases default to the "Administrator" user with ID -1
.
You can specify a Stream
for the contents of the file that should be created.
As an example, if you have an image on disk named unicorn.jpg
in the images folder of wwwroot
. You can open a new stream for a file on the disk, and then create a new media item for that file in Umbraco:
Please be aware that you will need to inject the following services:
MediaFileManager _mediaFileManager
IShortStringHelper _shortStringHelper
IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider
MediaUrlGeneratorCollection _mediaUrlGeneratorCollection
IMediaService _mediaService
IWebHostEnvironment _webHostEnvironment
Again Umbraco will make sure the necessary properties are updated.
The MemberGroupService acts as a "gateway" to Umbraco data for operations which are related to Member groups, which are also known as Member Roles.
.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the member group service in a class, you need to specify the IMemberGroupService
interface in your constructor:
In Razor views, you can access the member group service through the @inject
directive:
The MemberTypeService acts as a "gateway" to Umbraco data for operations which are related to MemberTypes.
.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the member type service in a class, you need to specify the IMemberTypeService
interface in your constructor:
In Razor views, you can access the member type service through the @inject
directive:
The RelationService
is pretty awesome as it allows you to create relations between objects that would otherwise have no obvious connection.
.
Namespace: Umbraco.Core.Services
Assembly: Umbraco.Core.dll
When you are using an Umbraco controller class (Such as SurfaceController
or RenderMvcController
) you have access to the RelationService
through the ServiceContext
:
You can also use the RelationService
in any other class by injecting its interface:
Checks if two items are related.
Returns bool
.
Checks if two items are related.
Returns bool
.
Checks if two items are related.
Returns bool
.
Deletes a relation.
Returns void
.
Deletes a relation type.
Returns void
.
Deletes relation of the specified relation type.
Returns void
.
Gets a collection of Umbraco.Core.Models.Relation
objects. Optional array of integer ids to return relations for.
Returns IEnumerable<IRelation>
.
Gets a collection of Umbraco.Core.Models.Relation
objects by their relation type.
Returns IEnumerable<IRelation>
.
Gets a collection of Umbraco.Core.Models.Relation
objects by their relation type id.
Returns IEnumerable<IRelation>
.
Gets a collection of Umbraco.Core.Models.Relation
objects. Optional array of integer ids to return relationtypes for.
Returns IEnumerable<IRelationType>
.
Gets a collection of Umbraco.Core.Models.Relation
objects by their child entity.
Returns IEnumerable<IRelation>
.
Gets a collection of Umbraco.Core.Models.Relation
objects their child entity and relation type alias.
Returns IEnumerable<IRelation>
.
Gets a collection of Umbraco.Core.Models.Relation
objects by their child id.
Returns IEnumerable<IRelation>
.
Gets a Umbraco.Core.Models.Relation
object by its id.
Returns IRelation
.
Gets a collection of Umbraco.Core.Models.Relation
objects by their parent entity and relation type alias.
Returns IEnumerable<IRelation>
.
Gets a collection of Umbraco.Core.Models.Relation
objects by their parent entity.
Returns IEnumerable<IRelation>
.
Gets a collection of Umbraco.Core.Models.Relation
objects by their parent id.
Returns IEnumerable<IRelation>
.
Gets a collection of Umbraco.Core.Models.Relation
objects by their parent or child id and relation type alias.
Returns IEnumerable<IRelation>
.
Using this method will get you all relations regards of it being a child or parent relation.
Gets a collection of Umbraco.Core.Models.Relation
objects by their parent or child id.
Returns IEnumerable<IRelation>
.
Using this method will get you all relations regards of it being a child or parent relation.
Gets a collection of Umbraco.Core.Models.Relation
objects by their relation type alias.
Returns IEnumerable<IRelation>
.
Gets a collection of Umbraco.Core.Models.Relation
objects by the id of their relation type.
Returns IEnumerable<IRelation>
.
Gets a collection of Umbraco.Core.Models.Relation
objects by the name of their relation type.
Returns IEnumerable<IRelation>
.
Gets the child objects from a collection of IRelation
as a collection of Umbraco.Core.Models.Entities.IUmbracoEntity
.
Returns IEnumerable<IUmbracoEntity>
.
Gets the child object from a relation as an Umbraco.Core.Models.Entities.IUmbracoEntity
object.
Returns IUmbracoEntity
.
Gets the parent and child objects from a relation as a System.Tuple
with Umbraco.Core.Models.Entities.IUmbracoEntity
.
Returns Tuple<IUmbracoEntity, IUmbracoEntity>
.
Gets the parent and child objects from a collection of relations as a list of Umbraco.Core.Models.Entities.IUmbracoEntity
objects.
Returns IEnumerable<Tuple<IUmbracoEntity, IUmbracoEntity>>
.
Gets the parent objects from a collection of relations as a collection of Umbraco.Core.Models.Entities.IUmbracoEntity
.
Returns IEnumerable<IUmbracoEntity>
.
Gets the parent object from a relation as an Umbraco.Core.Models.Entities.IUmbracoEntity
object.
Gets an relation by its alias.
Returns IRelationType
.
Gets a relation type by its Id
Returns IRelationType
.
Gets a relation type by its id.
Returns IRelationType
.
Checks if any relations exist for the specified relation type.
Returns bool
.
Checks if any relations exist for the specified id.
Returns void
.
Relates two objects by their ids using the specified relation type.
Returns IRelation
.
Relates two IUmbracoEntity
objects using the specified relation type.
Returns IRelation
.
Relates two IUmbracoEntity
objects using the specified relation type alias.
Returns IRelation
.
Relates two IUmbracoEntity
objects using the specified relation type alias.
Returns IRelation
.
Saves a relation.
Returns Void
.
Saves a relation type.
Returns Void
.
Below you will examples using the RelationService
.
Odd example, I know.. but why not?
To perform the said task we need a component in which we can register to the ContentService.Published
event:
To have Umbraco recognize our component we need to register it in a composer:
If I know Save and Publish
my Products
node I get the following result:
Cool! Now let us try and fetch the data from an API.
Notice the x => new Relation()
? We need to make sure what we are returning can be serialized. Therefore the Relation
class is:
Browsing /umbraco/api/relations/getbyrelationtypealias?alias=homesick
now returns the following:
If you want to do something similar to this it is recommended that you wrap a caching layer around it, as the RelationService queries the database directly.
()
The ServerRegistrationService manages server registrations in the database.
Browse the API documentation for IServerRegistrationService interface.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
The Umbraco.Core.dll allows you to reference the Constants classes used in the below examples.
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the server registration service in a class, you need to specify the IServerRegistrationService interface in your constructor:
In Razor views, you can access the server registration service through the @inject directive:
Content types can be added either at the root level, under another content type or under a content type container (or folders as they're called in the Umbraco backoffice). The approach for getting a single container is similar to getting a single content type, meaning that you can look up 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:
Tag service to query for tags in the tags db table.
Browse the API documentation for ITagService interface.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
In other cases, you may be able to use Dependency Injection. For instance if you have registered your own class in Umbraco's dependency injection, you can specify the ITagService
interface in your constructor:
In Razor views, you can access the member service through the @inject
directive:
In the example below, a new page is programmatically created using the content service. It is assumed that there are two document types, namely people and person. In this case, a new person is added underneath the people page.
The content type service acts as a "gateway" to Umbraco data for operations which are related to both content types and media types.
Browse the API documentation for IContentTypeService.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the content type service in a class, you need to specify the IContentTypeService
interface in your constructor:
In Razor views, you can access the content type service through the @inject
directive:
Retrieving content types See examples on how to retrieve content types via the service - either individually or as a collection.
Retrieving content type containers See examples on how to retrieve content type containers (folders) via the service - either individually or as a collection.
The ContentService acts as a "gateway" to Umbraco data for operations which are related to Content.
Browse the v9 API documentation for ContentService.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the content service in a class, you need to use Dependency Injection (DI) in your constructor:
In Razor views, you can access the content service through the @inject
directive:
The TextService is the entry point to localize any key in the text storage source for a given culture.
Browse the API documentation for ILocalizedTextService interface.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
In other cases, you may be able to use Dependency Injection. For instance if you have registered your own class in Umbraco's dependency injection, you can specify the ILocalizedTextService
interface in your constructor:
In Razor views, you can access the member service through the @inject
directive:
The localization service contains a number of methods for looking up languages. If you already know the ID of a specific language (eg. the default language has ID 1
), you can use the GetLanguageById
method to get the reference to that language:
Alternative, you can look up a language by its iso code via the GetLanguageByIsoCode
method:
The ISO code is a combination of the two-letter ISO 639-1 language code (lowercase) and two-letter ISO-3166 country code (uppercase). Eg. en-US
for English in the United States, en-GB
for English in the United Kingdom and da-DK
for Danish in Denmark.
Both methods will return an instance of the interface, which has traditional properties like Id
and Key
, but also properties specific to the language like CultureName
, CultureInfo
and IsoCode
. You can see the API reference for further information on the properties of the interface.
If you need instead need a list of all installed languages, you can use the GetAllLanguages
method. It takes no parameters, and as such a returns a collection of all languages (with no pagination like some of the other services):
As shown in the example above, you can get the System.Globalization.CultureInfo
instance of each language, which determines how numbers, dates and similar should be either parsed or formatted in .NET.
Below you can see a full example of the examples shown above - including the necessary imports:
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:
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 instead use the GetChildren
method - either 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:
This will show you how to create a new user using the UserService in Umbraco.
If you want to create a new user, you'd use ASP.NET identity APIs like it is used in core.
Permissions aren't administered for the specific user, but rather for the user group(s) that the user is a part of. So to add our new user to a user group, we first need to get a reference to the user via the GetUserGroupByAlias
method, and then use the AddGroup
method for adding the group to our user:
To make sure that these changed are saved to the database, we must also make sure to call the Save
method. The GetUserGroupByAlias
method takes the alias of a user group - eg. admin
for the default Administrators user group.
The LocalizationService acts as a "gateway" to Umbraco data for operations which are related to Dictionary items and Languages.
.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the localization service in a class, you need to specify the ILocalizationService
interface in your constructor:
In Razor views, you can access the localization service through the @inject
directive:
The UserService acts as a "gateway" to Umbraco data for operations which are related to Users.
Namespace: Umbraco.Core.Services
Assembly: Umbraco.Core.dll
All samples listed in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
If you wish to use the UserService in a class that inherits from one of the Umbraco base classes (eg. SurfaceController
, UmbracoApiController
or UmbracoAuthorizedApiController
), you can access the service through a local Services
property:
In other cases, you may be able to use Dependency Injection. For instance if you have registered your own class in Umbraco's dependency injection, you can specify the IUserService
interface in your constructor:
If neither a Services
property or Dependency Injection is available, you can also reference the static Current
class directly:
See examples on how to retrieve languages via the localization service - either individually or as a collection.
Quick sample showing how to create a new backoffice user; including setting a password, assigning the user to a user group, and setting the name of the user.