Content

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:

using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;

Constructors

new Content(string name, IContent parent, IContentType contentType, string culture = null)

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.

new Content(string name, IContent parent, IContentType contentType, int userId, string culture = null)

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.

new Content(string name, IContent parent, IContentType contentType, PropertyCollection properties, string culture = null)

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.

new Content(string name, int parentId, IContentType contentType, string culture = null)

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.

new Content(string name, int parentId, IContentType contentType, int userId, string culture = null)

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.

new Content(string name, int parentId, IContentType contentType, PropertyCollection properties, string culture = null)

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.

Properties

.CreateDate

Gets or Sets a DateTime object, indicating then the given Content was created.

.CreatorId

Gets or Sets the Id of the User who created the Content.

.ContentType

Returns a ISimpleContentType object representing the DocumentType used by the given Content.

.ContentTypeId

Returns the id as an int of the ContentType object representing the DocumentType used by the given Content.

.Id

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.

.Key

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.

.PublishedCultures

Gets Languages of the Content as a IEnumerable<string>.

.Level

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.

.Name

Gets or Sets the name of the content as a String.

.ParentId

Gets or Sets the parent Content Id as an Int.

.Path

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.

.Properties

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.

.Published

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.

.PublishDate

If set, returns DateTime? indicating when the Content should be published and made available on the website and cache.

.SortOrder

Returns the given Content index, compared to sibling content.

.PublishedState

Returns a IPublishedState enum with the status of the Content being either Unpublished, Published, Publishing, Unpublishing.

.TemplateId

Gets or sets the template id used to render the content.

.Trashed

Returns a Bool indicating whether the given Content is currently in the recycle bin.

.UpdateDate

Gets or Sets a DateTime object, indicating when the given Content was last updated.

.VersionId

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.

.WriterId

Gets or Sets the Id of the User who made the latest edit on the Content.

Methods

.GetCreatorProfile(IUserService userService)

Gets the IProfile object for the Creator of this Content, which contains the Id and Name of the User who created this Content item.

.GetValue(string propertyTypeAlias)

Gets the value of a Property as an Object.

.GetValue< TPassType >(string propertyTypeAlias)

Gets the value of a Property as the defined type 'TPassType'.

.GetWriterProfile(IUserService userService)

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.

.HasProperty(string propertyTypeAlias)

Returns a Bool indicating whether the Content object has a property with the supplied alias.

.SetValue(string propertyTypeAlias, object value)

Sets the value of a property by its alias.

.ToXml(IEntityXmlSerializer serializer)

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.

Last updated