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...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Represents a Dictionary Item. A Dictionary Item is what you see in the Translation / Dictionary tree.
Represents a Dictionary Item. A Dictionary Item is what you see in the Translation / Dictionary tree.
Namespace: Umbraco.Cms.Core.Models
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 statement:
Constructor for creating a new DictionaryItem
object where the necessary parameter is the key of the DictionaryItem
as a string
.
Constructor for creating a new DictionaryItem
object where the necessary parameters are the parentKey as Guid
and the key of the DictionaryItem
as a string
. Use this one if you want to create a DictionaryItem
underneath another one.
Gets or sets the Key for the Dictionary Item.
Gets or Sets a Guid?
of the Dictionary Item ParentId.
Gets or sets a IEnumerable<IDictionaryTranslation>
of translations for the Dictionary Item.
The Content class represents a single item in the content tree, its values are fetched directly from the database, not from the cache.
The Content
class represents a single item in the content tree, its values are fetched directly from the database, not from the cache. Notice the Content class should strictly be used for CRUD operations, not complex queries, as it is not flexible nor fast enough for this.
All content is versioned, so on each individual change, a new version is stored. Past versions can only be retrieved from the Content
api, not from the cache.
Namespace: Umbraco.Cms.Core.Models
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:
Constructor for creating a new Content object where the necessary parameters are the name of the Content, the parent of the Content as an IContent
object and the ContentType as an IContentType
object for the Content being created. In addition, there is an optional parameter for the culture.
Constructor for creating a new Content object where the necessary parameters are the name of the Content, the parent of the Content as an IContent
object, the ContentType as an IContentType
object for the Content being created and the id of the user as a int
. In addition, there is an optional parameter for the culture.
Constructor for creating a new Content object where the necessary parameters are the name of the Content, the parent of the Content as an IContent
object, the ContentType as an IContentType
object and a PropertyCollection
for the Content being created. In addition, there is an optional parameter for the culture.
Constructor for creating a new Content object where the necessary parameters are the name of the Content, the id of the parent as int
and the ContentType as an IContentType
object for the Content being created. In addition, there is an optional parameter for the culture.
Constructor for creating a new Content object where the necessary parameters are the name of the Content, the parent id of the Content as an int
object, the ContentType as an IContentType
object for the Content being created and the id of the user as a int
. In addition, there is an optional parameter for the culture.
Constructor for creating a new Content object where the necessary parameters are the name of the Content, the id of the parent as int
, the ContentType as an IContentType
object and a PropertyCollection
for the Content being created.In addition, there is an optional parameter for the culture.
Gets or Sets a DateTime
object, indicating then the given Content was created.
Gets or Sets the Id of the User
who created the Content.
Returns a ISimpleContentType
object representing the DocumentType used by the given Content
.
Returns the id as an int
of the ContentType
object representing the DocumentType used by the given Content
.
Returns the unique Content
Id as a Int
, this ID is based on a Database identity field, and is therefore not safe to reference in code which are moved between different instances, use Key instead.
Returns the Guid
assigned to the Content during creation. This value is unique, and should never change, even if the content is moved between instances.
Gets Languages of the Content as a IEnumerable<string>
.
Gets or Sets the given Content
level in the site hierarchy as an Int
. Content placed at the root of the site, will return 1, content right underneath will return 2, and so on.
Gets or Sets the name of the content as a String
.
Gets or Sets the parent Content
Id as an Int
.
Gets or Sets the path of the content as a String
. This string contains a comma separated list of the ancestor Ids including the current contents own id at the end of the string.
Gets or Sets the IPropertyCollection
object, which is a collection of IProperty
objects. Each property corresponds to a PropertyType
, which is defined on the ContentType
.
Returns a Bool
indicating whether the given Content
is published and available on the website or not. Notice: the published flag does not check the current in-memory cache, so this flag is not a guarantee that the Content is/is not available in the cache and the frontend of the website.
If set, returns DateTime?
indicating when the Content
should be published and made available on the website and cache.
Returns the given Content
index, compared to sibling content.
Returns a IPublishedState
enum with the status of the Content being either Unpublished, Published, Publishing, Unpublishing.
Gets or sets the template id used to render the content.
Returns a Bool
indicating whether the given Content
is currently in the recycle bin.
Gets or Sets a DateTime
object, indicating when the given Content was last updated.
Returns the current Version Id as a int
, for each change made to a content item, its values are stored under a new Version. This version is identified by a int
.
Gets or Sets the Id of the User
who made the latest edit on the Content.
Gets the IProfile
object for the Creator of this Content, which contains the Id and Name of the User who created this Content item.
Gets the value of a Property as an Object
.
Gets the value of a Property as the defined type 'TPassType'.
Gets the IProfile
object for the Writer of this Content, which contains the Id and Name of the User who last updated this Content item.
Returns a Bool
indicating whether the Content object has a property with the supplied alias.
Sets the value of a property by its alias.
Returns an XElement
containing the Content data, based off the latest changes. Is used when the published content is sent to the in-memory xml cache.
The Media class represents a single item in the media tree.
The Media
class represents a single item in the media tree, its values are fetched directly from the database, not from the cache. Notice the Media class should strictly be used for CRUD operations. Media is already stored in cache, so for querying Media you'd want to use the IUmbracoContext.IPublishedMediaCache
to get the media. Then one would use LINQ to query and filter the collection.
Namespace: Umbraco.Cms.Core.Models
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:
Constructor for creating a new Media object where the necessary parameters are the name of the Media, the parent of the Media as an IMedia
object and the MediaType as an IMediaType
object for the Media being created.
Constructor for creating a new Media object where the necessary parameters are the name of the Media, the parent of the Media as an IMedia
object, the MediaType as an IMediaType
object and a IPropertyCollection
for the Media being created.
Constructor for creating a new Media object where the necessary parameters are the name of the Media, the id of the parent as int
and the MediaType as an IMediaType
object for the Media being created.
Constructor for creating a new Media object where the necessary parameters are the name of the Media, the id of the parent as int
, the MediaType as an IMediaType
object and a IPropertyCollection
for the Media being created.
Gets or Sets a DateTime
object, indicating then the given Media was created.
Gets or Sets the Id of the User
as an int
who created the Media.
Returns a ISimpleContentType
object representing the ContentType used by the given Media
.
Returns the id as an int
of the MediaType
object representing the ContentType used by the given Media
.
Returns the unique Media
Id as a Int
, this ID is based on a Database identity field, and is therefore not safe to reference in code which are moved between different instances, use Key instead.
Returns the Guid
assigned to the Media during creation. This value is unique, and should never change, even if the Media is moved between instances.
Gets or Sets the given Media
level in the site hierarchy as an Int
. Media placed at the root of the tree, will return 1, Media right underneath will return 2, and so on.
Gets or Sets the name of the Media as a String
.
Gets or Sets the parent Media
Id as an Int
.
Gets or Sets the path of the Media as a String
. This string contains a comma separated list of the ancestors Ids including the current medias own id at the end of the string.
Gets or Sets the PropertyCollection
object, which is a collection of Property
objects. Each property corresponds to a PropertyType
, which is defined on the MediaType
.
Returns the given Media
index, compared to sibling media.
Returns a Bool
indicating whether the given Media
is currently in the recycle bin.
Gets or Sets a DateTime
object, indicating when the given Media was last updated.
Returns the current Version Id as a Guid
, For each change made to a Media item, its values are stored under a new Version. This version is identified by a Guid
.
Changes the IMediaType
for the current Media object and removes PropertyTypes and Properties, which are not part of the new MediaType
. Please use with caution as this remove differences between the new and old MediaType.
Gets the IProfile
object for the Creator of this Media, which contains the Id and Name of the User who created this Media item.
Gets the value of a Property as an Object
.
Gets the value of a Property as the defined type 'TPassType'.
Returns a Bool
indicating whether the Media object has a property with the supplied alias.
Sets the value of a property by its alias.
It is worth noting that it is also possible to pass a HttpPostedFile, HttpPostedFileBase or HttpPostedFileWrapper to the SetValue method, so it can be used for uploads.
Returns an XElement
containing the Media data, based off the latest changes. When the Media item is saved the xml is stored in the database.
Represents a Relation between two items.
Represents a Relation between two items.
Namespace: Umbraco.Cms.Core.Models
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 statement:
Constructor for creating a new Relation object. The necessary parameters are the Id of the parent item as an int
, the Id of the child as an int
and the relationType as IRelationType
.
A second constructor exists but it should not be used because it is used to reconstruct a relation from the data source.
Gets or sets the Child Id of the Relation (Destination)
Gets or sets a comment for the Relation
Gets or sets the Parent Id of the Relation (Source)
Gets or sets the RelationType for the Relation
Gets the Id of the RelationType that this Relation is based on.
Represents a Language. Installed languages can be found in the settings section.
Represents a Language. Installed languages can be found in the settings section.
Namespace: Umbraco.Cms.Core.Models
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 statement:
Constructor for creating a new Language
object where the necessary parameter are the global settings as GlobalSettings
and the isoCode as a string
.
To create a new Language the global setting parameter is necessary. You can find more info about how to use configuration in code in the Config article.
Gets the CultureInfo object for the language.
Gets or sets the culture name of the language.
Gets or sets the identifier of a fallback language. The fallback language can be used in multi-lingual scenarios, to help define fallback strategies when a value does not exist for a requested language.
Gets or sets a value indicating whether the language is the default language.
Gets or sets a value indicating whether the language is mandatory. When a language is mandatory, a multi-lingual document cannot be published without that language being published, and unpublishing that language unpublishes the entire document.
Gets or sets the ISO code of the language.
A MediaType is almost the same as a ContentType. I.e. a model / data definition for your media nodes.
A MediaType is almost the same as a ContentType, that is, a model / data definition for your media nodes
You can set icon, thumbnail and description. It is also possible to add groups and properties.
A Media Type differs from a Document Type in that it has no templates.
Namespace: Umbraco.Cms.Core.Models
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:
Constructor for creating a new MediaType
object where the necessary parameters are a short string helper IShortStringHelper
and the Id of the parent MediaType
as an Int
.
Constructor for creating a new MediaType
object where the necessary parameter are a short string helper IShortStringHelper
and the parent MediaType
as an IMediaType
object.
This constructor creates a new MediaType
object and requires the following parameters: a short string helper IShortStringHelper
and the parent MediaType
as an IMediaType
object. Additionally, the alias of the MediaType
should be provided as a string
.
Gets or Sets the Alias as a String
of the MediaType.
Gets or Sets an Enumerable
list of ContentTypeSort
objects of the MediaTypes allowed under the current MediaType.
The ContentTypeSort
is an object with a lazy Id, int SortOrder and string Alias used to sort the MediaTypes within the list of AllowedContentTypes.
Gets a list of MediaTypes
as IContentTypeComposition
objects that make up a composition of PropertyGroups and PropertyTypes for the current MediaType.
The ContentTypeComposition
provides a mixin-type functionality in that you can compose a MediaType of one or more other MediaTypes in a complex structure. But please keep in mind that the backoffice does not fully support these complex structures yet
Gets a list of all PropertyGroup
objects from the composition including PropertyGroups from the current MediaType.
Gets a list of all PropertyType
objects from the composition including PropertyTypes from the current MediaType.
Gets or Sets a DateTime
object, indicating then the given MediaType was created.
Gets or Sets the Id of the User
who created the MediaType.
Gets or Sets the Description as a String
for the MediaType.
Gets or Sets the Icon as a String
for the MediaType.
Retrieves the unique MediaType
ID as an Int
. This ID is based on a Database identity field and is therefore not safe to reference in code when moved between different instances.
Gets the Guid
assigned to the MediaType during creation. This value is unique, and should never change, even if the content is moved between instances.
Gets or Sets the given MediaType
level in the site hierarchy as an Int
. MediaTypes placed at the root of the tree, will return 1, content right underneath will return 2, and so on.
Gets or Sets the name of the MediaType as a String
.
Gets or Sets the parent MediaType
Id as an Int
.
Gets or Sets the path of the MediaType as a String
. This string contains a comma separated list of the ancestor Ids including the current MediaTypes own id at the end of the string.
Gets or Sets a PropertyGroupCollection
containing a list of PropertyGroups for the current MediaType.
Gets an Enumerable
list of PropertyTypes aggregated for all groups within the current MediaType, as well as PropertyTypes not within a group.
Gets the given MediaType
index, compared to sibling content.
Gets or Sets the Thumbnail as a String
for the MediaType.
Adds a new MediaType
to the list of composite MediaTypes.
Returns an Enumerable
list of MediaType aliases as String
from the current composition.
Returns an Enumerable
list of MediaType Ids as Int
from the current composition.
Checks if a MediaType
with the supplied alias exists in the list of composite MediaTypes.
Removes a MediaType
with the supplied alias from the list of composite MediaTypes.
Removes a PropertyType
from the current MediaType
.
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 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:
Details of CRUD operations within Umbraco and how to interact with the data persisted in the database
The intended audience for these reference pages are .NET developers. It is assumed the reader already has knowledge of the basics of Umbraco and knows .NET & C#.
Since the release of Umbraco 10, we will no longer be updating the articles in this section.
You can find up-to-date code references for all Models in our API Documentation.
Here you will find references for the models in the public API. The models include Content, ContentType, DataTypeDefinition, DictionaryItem, Language, Media, MediaType, Relation, RelationType, Task, TaskType, and Template classes.
Here you will find references for the services which are available for performing Create, Read, Update and Delete (CRUD) operations for the models mentioned above.
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:
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 `RelationType` class represents a relation definition between two node types (content or media).
The RelationType
class represents a relation definition between two node types (content or media). For example keeping track of node usage across the site, in order to avoid deleting content that is used else where. When querying a relation, it is typically done using the parent node key. However, if the RelationType
is bidirectional, querying with the child node key is also possible.
Namespace: Umbraco.Cms.Core.Models
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 statement:
Create a new RelationType object with this constructor. It requires a string
alias, the relation type's name, and a bool
for bidirectionality. Additionally, specify the Guid?
keys for both child and parent object types involved in the relation.
Gets or sets the Name of the RelationType as a String
.
Gets or sets the Alias of the RelationType as String
.
Gets or sets a boolean
indicating whether the RelationType is Bidirectional (true) or Parent to Child (false)
Gets or sets the Parents object type key as Guid?
Gets or sets the Childs object type key as Guid?
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:
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 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:
A ContentType corresponds to the Document Type found in the backoffice.
A ContentType corresponds to the Document Type found in the backoffice. The ContentType is a model / data definition for your content nodes. Every content node on an Umbraco web site always maps to a backing Document Type.
A Document Type is composed by Properties, which are grouped by Tabs (or PropertyGroups in the API). It can also inherit properties and tabs from other Document Types.
It is possible to link one or more Templates to a Document Type. This determines how your model/data is rendered to the user.
Namespace: Umbraco.Cms.Core.Models
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:
Constructor for creating a new ContentType
object. The necessary parameters are a short string helper IShortStringHelper
, the parent ContentType
as an IContentType
and the alias of the new ContentType
as string
.
Constructor for creating a new ContentType
object where the necessary parameters are a short string helper IShortStringHelper
and the Id of the parent ContentType
as an Int
.
Gets or Sets the Alias as a String
of the ContentType.
Gets or Sets a Bool
indicating whether this ContentType is allowed at the root. If one or more ContentTypes are set to 'AllowedAsRoot' only they are shown in the create dialog at the root level in the backoffice.
Gets or Sets an Enumerable
list of ContentTypeSort
objects of the ContentTypes allowed under the current ContentType.
The ContentTypeSort
is an object with a lazy Id, int SortOrder and string Alias used to sort the MediaTypes within the list of AllowedContentTypes.
Gets or Sets an Enumerable
list of ITemplates
which are allowed for the current ContentType.
Gets a list of ContentTypes
as IContentTypeComposition
objects that make up a composition of PropertyGroups and PropertyTypes for the current ContentType.
The ContentTypeComposition provides a mixin-type functionality in that you can compose a ContentType of one or more other ContentTypes in a complex structure. But please be aware that the backoffice does not fully support these complex structures yet.
Gets a list of all 'PropertyGroup` objects from the composition including PropertyGroups from the current ContentType.
Gets a list of all PropertyType
objects from the composition including PropertyTypes from the current ContentType.
Gets or Sets a DateTime
object, indicating then the given ContentType was created.
Gets or Sets the Id of the User
who created the ContentType.
Gets or Sets the Description as a String
for the ContentType.
Gets the default Template set as an ITemplate
object for this ContentType.
Gets or Sets the Icon as a String
for the ContentType.
Gets the unique ContentType
Id as an Int
. The ID, derived from a database identity field, isn't safe for code references as they are moved across instances. Therefore it's recommended to use Key
instead.
Gets the Guid
assigned to the ContentType during creation. This value is unique, and should never change, even if the content is moved between instances.
Gets or Sets the given ContentType
level in the site hierarchy as an Int
. ContentTypes placed at the root of the tree, will return 1, content right underneath will return 2, and so on.
Gets or Sets the name of the ContentType as a String
.
Gets or Sets the parent ContentType
Id as an Int
.
Gets or Sets the path of the ContentType as a String
. This string contains a comma separated list of the ancestors Ids including the current ContentTypes own id at the end of the string.
Gets or Sets a PropertyGroupCollection
containing a list of PropertyGroups for the current ContentType.
Gets an Enumerable
list of PropertyTypes aggregated for all groups within the current ContentType, as well as PropertyTypes not within a group.
Gets the given ContentType
index, compared to sibling content.
Gets or Sets the Thumbnail as a String
for the ContentType.
Adds a new ContentType
to the list of composite ContentTypes.
Returns an Enumerable
list of ContentType aliases as String
from the current composition.
Returns an Enumerable
list of ContentType Ids as Int
from the current composition.
Checks if a ContentType
with the supplied alias exists in the list of composite ContentTypes.
Sets the default Template
for the current ContentType.
Removes a ContentType
with the supplied alias from the list of composite ContentTypes.
Removes a PropertyType
from the current ContentType
.
Removes a Template
from the list of allowed templates.
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:
Represents a registered server in a multiple-servers environment.
The ServerRegistration
class represents a registered server in a multiple-servers environment.
Namespace: Umbraco.Cms.Core.Models
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 statement:
Constructor for creating a new ServerRegistration object. The necessary parameters are the serverAddress as a string
, the serverIdentity as a string
and the date and time of registration as a DateTime
A second constructor exists but it should not be used because it is used to reconstruct a ServerRegistration
from the data source.
Gets the date and time the registration was last accessed.
Gets or sets a value indicating whether the server is active.
Gets or sets a value indicating whether the server has the SchedulingPublisher role
Gets the date and time the registration was created.
Gets or sets the server URL.
Gets or sets the server unique identity.
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 ExternalLoginService is used to store the external login info and can be replaced with your own implementation.
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:
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 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 RedirectUrlService is used for CRUD operations related to Redirects.
Browse the API documentation for IRedirectUrlService 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 IRedirectUrlService
interface in your constructor:
In Razor views, you can access the member service through the @inject
directive:
Service to handle public access.
Browse the API documentation for IPublicAccessService 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 IPublicAccessService
interface in your constructor:
In Razor views, you can access the member service through the @inject
directive:
Represents a Template file.
Represents a Template file.
Namespace: Umbraco.Cms.Core.Models
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:
Constructor for creating a new Template object. The necessary parameters include a short String Helper as an IShortStringHelper
. The name and alias of the Template must be provided as string
values.
Gets the Alias of the File, which is the name without the extension.
Returns true if the template is used as a layout for other templates (that is, it has 'children')
Returns the alias of the master template if one is set.
Returns the id of the master template if one is set.
Gets the Name of the File including extension.
Sets the master template of the template.
The MediaService acts as a "gateway" to Umbraco data for operations which are related to media.
Browse the API documentation for IMediaService interface.
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.
Browse the API documentation for IMemberGroupService.
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:
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:
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:
The MemberTypeService acts as a "gateway" to Umbraco data for operations which are related to MemberTypes.
Browse the API documentation for IMemberTypeService 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 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:
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.
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:
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.
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:
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 ILanguage 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:
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 LocalizationService acts as a "gateway" to Umbraco data for operations which are related to Dictionary items and Languages.
Browse the API documentation for ILocalizationService.
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:
Retrieving languages See examples on how to retrieve languages via the localization service - either individually or as a collection.
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:
Create a new user 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.
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.
A DataType is what you see in the backoffice in the Settings / DataTypes tree. The listed nodes are definitions of the DataTypes that are available to use on your PropertyTypes.
A DataType is what you see in the backoffice in the Settings / DataTypes tree. The listed nodes are definitions of the DataTypes that are available to use on your PropertyTypes.
Namespace: Umbraco.Cms.Core.Models
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 statement:
Constructor for creating a new DataType
object where the necessary parameters are a IDataEditor
and a IConfigurationEditorJsonSerializer
. Optionally, the parentId can be added, if not provided the default value is -1, which means it will be created at root level.
Gets or Sets a DateTime
object, indicating then the given DataType was created.
Gets or Sets the Id of the User
who created the DataType.
Gets or Sets the DatabaseType as a ValueStorageType
enum for which the DataType's value is saved as.
Returns the unique DataType
ID as an Int
. The ID, derived from a database identity field, isn't safe for code references as they are moved across instances. Therefore it's recommended to use Key
instead.
Returns the Guid
assigned to the DataType during creation. This value is unique, and should never change, even if the DataType is moved between instances.
Gets or Sets the given DataType
level in the site hierarchy as an Int
. DataType placed at the root of the site, will return 1, DataType right underneath will return 2, and so on.
Gets or Sets the name of the DataType
as a String
.
Gets or Sets the parent DataType
Id as an Int
.
Gets or Sets the path of the DataType
as a String
. This string contains a comma separated list of the ancestor Ids including the current contents own id at the end of the string.
Returns the given DataType
index, compared to sibling DataType.
Returns a Bool
indicating whether the given DataType
is currently in the recycle bin.
The RelationService
is pretty awesome as it allows you to create relations between objects that would otherwise have no obvious connection.
Browse the API documentation for IRelationService interface.
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:
(You can read more about composing Umbraco here)
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.