Applies to Umbraco 6.x and newer
The ContentService acts as a "gateway" to Umbraco data for operations which are related to Content.
Browse the API documentation for ContentService.
- Namespace:
Umbraco.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 usings:
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
Please note that this page will be updated with samples and additional information about the methods listed below
The ContentService is available through the ApplicationContext, but if you are using a SurfaceController or the UmbracoUserControl then the ContentService is available through a local Services property.
Services.ContentService
Getting the service through the ApplicationContext:
ApplicationContext.Current.Services.ContentService
Assigns a single permission to the current Content object for the specified list of user IDs.
Copies an Content object by creating a new Content object of the same type and copies all data from the current to the new copy which is returned.
Count all Content objects with given ContentType.
Count all Children for given parent Content object with ContentType.
Count all Descendants for given parent Content object with ContentType.
Count all Content objects Published with ContentType.
Creates a Content object using the alias of the ContentType that this Content is based on.
Creates a Content object using the alias of the ContentType that this Content is based on.
Creates and saves an Content object using the alias ContentType that this Content should be based on.
Creates and saves an Content object using the alias ContentType that this Content should be based on.
Permanently deletes a Content object.
Deletes all content of specified type. All children of deleted content is moved to Recycle Bin.
Permanently deletes a specific version from an Content object.
Permanently deletes versions from an Content object prior to a specific date.
Empties the Recycle Bin by deleting all Content that resides in the bin.
Gets an Enumerable list of Content objects for given Content object.
Gets an Enumerable list of Content objects for given Content object ID.
Gets an Content object by Id as Int.
Gets an Content object by Key as Guid. The Key corresponds to the 'UniqueId' column in the umbracoNode table in the database.
Gets an Enumerable list of Content objects for given Enumerable list of Content object IDs.
Gets an Enumerable list of Content objects by the Id of the ContentType.
Gets an Enumerable list of Content objects by Level.
Gets an Enumerable list of child Content objects by their parents Id.
Gets an Enumerable list of Content objects, which reside at the first level / root.
Gets an Enumerable list of an Content objects versions by its Id.
Gets an Enumerable list of Content objects, which has an expiration date greater then today.
Gets an Enumerable list of Content objects, which has a release date greater then today.
Gets an Enumerable list of an Content objects, which resides in the Recycle Bin.
Gets an Enumerable list of Content objects by its name or partial name.
Gets an Enumerable list of descendant Content objects by Parent Id.
Gets an Enumerable list of Content objects by Parent Id.
Gets a specific version of a Content item.
.GetPagedChildren(int id, int pageIndex, int pageSize, out int totalChildren, string orderBy, Direction orderDirection, [string filter = ""])
Gets an Enumerable list of Content child objects, paged.
.GetPagedDescendants(int id, int pageIndex, int pageSize, out int totalChildren, [string orderBy = "Path"], [Direction orderDirection = Direction.Ascending], [string filter = ""])
Gets an Enumerable list of Content descendant objects, paged.
Get parent Content object, by Content object.
Get parent Content object, by Content ID.
Gets a collection of EntityPermission permission objects for the Content item.
Gets the published version of a Content item.
Gets a collection of Content objects, which reside at the first level / root
Checks whether a Content item has any children. Returns a bool.
Checks whether an Content item has any published versions. Returns a bool.
Checks if the passed in Content can be published based on the ancestors publish state. Returns a bool.
Moves an Content object to a new location.
Deletes an Content object by moving it to the Recycle Bin.
Publishes a single Content object
Publishes a Content object and all its children.
.PublishWithChildrenWithStatus(IContent content, [int userId = 0], [bool includeUnpublished = false])
Publishes a Content object and all its children, returning a collection of <Attempt<PublishStatus>>.
Publishes a Content object, returning the result as a Attempt<PublishStatus>.
Rebuilds all xml content in the cmsContentXml table for all documents matching the IDs passed in. If none then rebuilds the structures for all content.
Replaces the PermissionSet for Content.
Re-Publishes all Content.
Rollback an Content object to a previous version. This will create a new version, which is a copy of all the old data.
Saves a single IContent object.
Saves an Enumerable list of Content objects.
Saves and Publishes a single Content object.
Saves and Publishes a single Content object, returning the result as a Attempt<PublishStatus>.
Sends a Content item to Publication, which executes handlers and events for the 'Send to Publication' action.
Returns True if sending publication was succesful, otherwise False.
Sorts a collection Content objects by updating the SortOrder according to the ordering of items in the passed in System.Collections.Generic.IEnumerable. Returns True if sorting succeeded, otherwise False. Using this method will ensure that the Published-state is maintained upon sorting so the cache is updated accordingly - as needed.
UnPublishes a single Content object.