November Happy Hour will be moved to Thursday December 5th.

Class ContentRepository

Defines repository methods for IContent objects.

Inheritance
System.Object
ContentRepository
Namespace: EPiServer.Core.Internal
Assembly: EPiServer.dll
Version: 12.0.3
Syntax
public abstract class ContentRepository : Object, IContentRepository, IContentLoader

Constructors

ContentRepository()

Declaration
protected ContentRepository()

Methods

Copy(ContentReference, ContentReference, AccessLevel, AccessLevel, Boolean)

Creates a copy of a content and it's eventual children and adds the new content(s) under the specialized destination first ensuring that the current user meets the minimal access right requirements.

Declaration
public abstract ContentReference Copy(ContentReference source, ContentReference destination, AccessLevel requiredSourceAccess, AccessLevel requiredDestinationAccess, bool publishOnDestination)
Parameters
Type Name Description
ContentReference source

The content that should be copied.

ContentReference destination

The destination where the content will be copied as a child to.

AccessLevel requiredSourceAccess

The access rights required on the source content that is to be copied.

AccessLevel requiredDestinationAccess

The access rights required on the destination.

System.Boolean publishOnDestination

If the new content(s) should be published on the destination.

Returns
Type Description
ContentReference

A reference to the new copy of the content.

Remarks

If publishOnDestination is true the new page will be published immediately at the destination.

CreateLanguageBranch<T>(ContentReference, CultureInfo)

Creates a new language branch for a content item in the specified language first ensuring that the current user meets the minimal access right requirements.

Declaration
public abstract T CreateLanguageBranch<T>(ContentReference contentLink, CultureInfo language)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

The link to the content to create a language branch for.

System.Globalization.CultureInfo language

The language.

Returns
Type Description
T

An IContent object for the newly created content in the specified language.

Type Parameters
Name Description
T

The type of content to create.

Remarks

Access checks are performed during Save. CreateLanguageBranch method returns not persisted in-memory instance.

Delete(ContentReference, Boolean, AccessLevel)

Deletes a content from the repository first ensuring that the current user meets the minimal access right requirements.

Declaration
public abstract void Delete(ContentReference contentLink, bool forceDelete, AccessLevel access)
Parameters
Type Name Description
ContentReference contentLink

The content link.

System.Boolean forceDelete

If set to true, deletes the content even if it is being referenced by other content.

AccessLevel access

The required access level that the current user must have to be allowed to delete the content.

Exceptions
Type Condition
AccessDeniedException

Thrown when user doesn't have access right to perform this action.

DeleteChildren(ContentReference, Boolean, AccessLevel)

Deletes all the children of a content from the repository, first ensuring that the current user meets the minimal access right requirements.

Declaration
public abstract void DeleteChildren(ContentReference contentLink, bool forceDelete, AccessLevel access)
Parameters
Type Name Description
ContentReference contentLink

The content link.

System.Boolean forceDelete

If set to true, deletes child even if they are being referenced by other content items..

AccessLevel access

The required access level that the current user must have to be allowed to delete the child.

Exceptions
Type Condition
AccessDeniedException

Thrown when user doesn't have access right to perform this action. Permission to all affected children are checked before any content is deleted.

DeleteLanguageBranch(ContentReference, String, AccessLevel)

Deletes the specified language branch for a content from the repository first ensuring that the current user meets the minimal access right requirements.

Declaration
public abstract void DeleteLanguageBranch(ContentReference contentLink, string languageBranch, AccessLevel access)
Parameters
Type Name Description
ContentReference contentLink

The link to the page which will be deleted.

System.String languageBranch

The language branch to delete.

AccessLevel access

The required access level that the current user must have on the page to be allowed to delete the language branch.

Get<T>(ContentReference)

Gets the content item represented by the provided reference.

Declaration
public abstract T Get<T>(ContentReference contentLink)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

The link to the content.

Returns
Type Description
T

The requested content item, as the specified type.

Type Parameters
Name Description
T

The type of content to get.

Exceptions
Type Condition
TypeMismatchException

Is thrown if actual type is not assignable to T.

ContentNotFoundException

Is thrown if there is no IContent instance with contentLink as id.

Get<T>(ContentReference, LoaderOptions)

Gets the content item represented by the provided reference given by the provided context.

Declaration
public abstract T Get<T>(ContentReference contentLink, LoaderOptions loaderOptions)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

The link to the content.

LoaderOptions loaderOptions

The settings that specifies how the content should be loaded, e.g. the language to get the content in.

Returns
Type Description
T

The requested content, as the specified type, in the specified language.

Type Parameters
Name Description
T

The type of content to get.

Exceptions
Type Condition
TypeMismatchException

Is thrown if actual type is not assignable to T.

ContentNotFoundException

Is thrown if there is no IContent instance with contentLink as id.

Get<T>(ContentReference, CultureInfo)

Gets the specific language of content item represented by the provided reference.

Declaration
public abstract T Get<T>(ContentReference contentLink, CultureInfo language)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

The link to the content.

System.Globalization.CultureInfo language

The language

Returns
Type Description
T

The requested content item, as the specified type.

Type Parameters
Name Description
T

The type of content to get.

Remarks

If the contentLink is a specific version (that is where WorkID is set) the language is ignored and that specific version is returned.

Exceptions
Type Condition
TypeMismatchException

Is thrown if actual type is not assignable to T.

ContentNotFoundException

Is thrown if there is no IContent instance with contentLink as id.

Get<T>(Guid)

Gets the content item represented by the provided GUID.

Declaration
public abstract T Get<T>(Guid contentGuid)
    where T : IContentData
Parameters
Type Name Description
System.Guid contentGuid

The content identifier.

Returns
Type Description
T

The requested content item, as the specified type.

Type Parameters
Name Description
T

The type of content to get.

Exceptions
Type Condition
TypeMismatchException

Is thrown if actual type is not assignable to T.

ContentNotFoundException

Is thrown if there is no IContent instance with contentGuid as id.

Get<T>(Guid, LoaderOptions)

Gets the content item represented by the provided GUID given by the provided context.

Declaration
public abstract T Get<T>(Guid contentGuid, LoaderOptions loaderOptions)
    where T : IContentData
Parameters
Type Name Description
System.Guid contentGuid

The content identifier.

LoaderOptions loaderOptions

The settings that specifies how the content should be loaded, e.g. the language to get the content in.

Returns
Type Description
T

The requested content item, as the specified type.

Type Parameters
Name Description
T

The type of content to get.

Exceptions
Type Condition
TypeMismatchException

Is thrown if actual type is not assignable to T.

ContentNotFoundException

Is thrown if there is no IContent instance with contentGuid as id.

Get<T>(Guid, CultureInfo)

Gets the specific language of content item represented by the provided reference.

Declaration
public abstract T Get<T>(Guid contentGuid, CultureInfo language)
    where T : IContentData
Parameters
Type Name Description
System.Guid contentGuid

The content identifier.

System.Globalization.CultureInfo language

The language.

Returns
Type Description
T

The requested content item, as the specified type.

Type Parameters
Name Description
T

The type of content to get.

Exceptions
Type Condition
TypeMismatchException

Is thrown if actual type is not assignable to T.

ContentNotFoundException

Is thrown if there is no IContent instance with contentGuid as id.

GetAncestors(ContentReference)

Retrieves all content items located above the specified content.

Declaration
public abstract IEnumerable<IContent> GetAncestors(ContentReference contentLink)
Parameters
Type Name Description
ContentReference contentLink

The reference to the item whose ancestors you want to retrieve.

Returns
Type Description
System.Collections.Generic.IEnumerable<IContent>

A list of all items located above the specified reference.

GetBySegment(ContentReference, String, LoaderOptions)

Gets the child IContentData instance that has a RouteSegment that matches urlSegment.

Declaration
public abstract IContent GetBySegment(ContentReference parentLink, string urlSegment, LoaderOptions settings)
Parameters
Type Name Description
ContentReference parentLink

The parent link.

System.String urlSegment

The URL segment.

LoaderOptions settings

The settings to use.

Returns
Type Description
IContent

The content instance that matches urlSegment or null if no match.

Remarks

It is the passed in settings that is responsible to handle fallback and replacement settings for language.

GetBySegment(ContentReference, String, CultureInfo)

Gets the child IContentData instance that has a RouteSegment that matches urlSegment.

Declaration
public abstract IContent GetBySegment(ContentReference parentLink, string urlSegment, CultureInfo language)
Parameters
Type Name Description
ContentReference parentLink

The parent link.

System.String urlSegment

The URL segment.

System.Globalization.CultureInfo language

The language

Returns
Type Description
IContent

The content instance that matches urlSegment or null if no match.

Remarks

It is the passed in language that is responsible to handle fallback and replacement settings for language.

GetChildren<T>(ContentReference)

Gets the children of the content item represented by the provided reference.

Declaration
public abstract IEnumerable<T> GetChildren<T>(ContentReference contentLink)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

A reference to the parent whose children should be returned.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

The children of the specifed parent, as the specified type.

Type Parameters
Name Description
T

The type of children to get.

GetChildren<T>(ContentReference, LoaderOptions)

Gets the children of the content item represented by the provided reference given by the provided context.

Declaration
public abstract IEnumerable<T> GetChildren<T>(ContentReference contentLink, LoaderOptions loaderOptions)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

A reference to the parent whose children should be returned.

LoaderOptions loaderOptions

The settings that specifies how the content should be loaded, e.g. the language to get the content in.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

The children of the specifed parent, as the specified type.

Type Parameters
Name Description
T

The type of children to get.

GetChildren<T>(ContentReference, LoaderOptions, Int32, Int32)

Gets the children of the content item represented by the provided reference given by the provided context.

Declaration
public abstract IEnumerable<T> GetChildren<T>(ContentReference contentLink, LoaderOptions loaderOptions, int startIndex, int maxRows)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

A reference to the parent whose children should be returned.

LoaderOptions loaderOptions

The settings that specifies how the content should be loaded, e.g. the language to get the content in.

System.Int32 startIndex

The index of the first child to return.

System.Int32 maxRows

The max number of children to return.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

The children of the specifed parent, as the specified type.

Type Parameters
Name Description
T

The type of children to get.

Remarks

This is the overload of GetChildren that supports paging.

GetChildren<T>(ContentReference, CultureInfo)

Gets the children of the content item represented by the provided reference given the language.

Declaration
public abstract IEnumerable<T> GetChildren<T>(ContentReference contentLink, CultureInfo language)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

A reference to the parent whose children should be returned.

System.Globalization.CultureInfo language

The language.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

The children of the specifed parent, as the specified type.

Type Parameters
Name Description
T

The type of children to get.

GetChildren<T>(ContentReference, CultureInfo, Int32, Int32)

Gets the children of the content item represented by the provided reference given the language.

Declaration
public abstract IEnumerable<T> GetChildren<T>(ContentReference contentLink, CultureInfo language, int startIndex, int maxRows)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

A reference to the parent whose children should be returned.

System.Globalization.CultureInfo language

The language.

System.Int32 startIndex

The index of the first child to return.

System.Int32 maxRows

The max number of children to return.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

The children of the specifed parent, as the specified type.

Type Parameters
Name Description
T

The type of children to get.

Remarks

This is the overload of GetChildren that supports paging.

GetDefault<T>(ContentReference)

Gets a new default instance of an IContentData object for the given type, placed at the location of the parent provided and initialized with the default values for the content type.

Declaration
public abstract T GetDefault<T>(ContentReference parentLink)
    where T : IContentData
Parameters
Type Name Description
ContentReference parentLink

The parent link.

Returns
Type Description
T

A IContent object for the given ContentType, initialized with the default values for the content type.

Type Parameters
Name Description
T

The type of content to create.

Exceptions
Type Condition
AccessDeniedException

Thrown when user doesn't have access right to perform this action

GetDefault<T>(ContentReference, CultureInfo)

Gets a new default instance of an IContentData object for the given type, placed at the location of the parent provided and initialized with the default values for the content type. The language of the content item is determined from the language.

Declaration
public abstract T GetDefault<T>(ContentReference parentLink, CultureInfo language)
    where T : IContentData
Parameters
Type Name Description
ContentReference parentLink

The parent link.

System.Globalization.CultureInfo language

The language of the created item.

Returns
Type Description
T

A IContent object for the given ContentType, initialized with the default values for the content type.

Type Parameters
Name Description
T

The type of content to create.

Exceptions
Type Condition
AccessDeniedException

Thrown when user doesn't have access right to perform this action

GetDefault<T>(ContentReference, Int32)

Gets a new default instance of an IContentData object for the given type, placed at the location of the parent provided and initialized with the default values for the content type. The language of the content item is determined from the language.

Declaration
public abstract T GetDefault<T>(ContentReference parentLink, int contentTypeID)
    where T : IContentData
Parameters
Type Name Description
ContentReference parentLink

The parent link.

System.Int32 contentTypeID

The ID of the content type that the content item should be created as.

Returns
Type Description
T

A IContent object for the given ContentType, initialized with the default values for the content type.

Type Parameters
Name Description
T

The type of content to create.

Exceptions
Type Condition
AccessDeniedException

Thrown when user doesn't have access right to perform this action

GetDefault<T>(ContentReference, Int32, CultureInfo)

Gets a new default instance of an IContentData object for the given type, placed at the location of the parent provided and initialized with the default values for the content type. The language of the content item is determined from the language.

Declaration
public abstract T GetDefault<T>(ContentReference parentLink, int contentTypeID, CultureInfo language)
    where T : IContentData
Parameters
Type Name Description
ContentReference parentLink

The parent link.

System.Int32 contentTypeID

The ID of the content type that the content item should be created as.

System.Globalization.CultureInfo language

The language of the created item.

Returns
Type Description
T

A IContent object for the given ContentType, initialized with the default values for the content type.

Type Parameters
Name Description
T

The type of content to create.

Exceptions
Type Condition
AccessDeniedException

Thrown AccessDeniedException when user doesn't have access right to perform this action

GetDescendents(ContentReference)

Gets references to the descendents of the specified content.

Declaration
public abstract IEnumerable<ContentReference> GetDescendents(ContentReference contentLink)
Parameters
Type Name Description
ContentReference contentLink

A reference to the parent whose descendents should be returned.

Returns
Type Description
System.Collections.Generic.IEnumerable<ContentReference>

A list of references to all the descendent of specified content.

GetItems(IEnumerable<ContentReference>, LoaderOptions)

Gets all content items that is represented by the provided references given by the provided context.

Declaration
public abstract IEnumerable<IContent> GetItems(IEnumerable<ContentReference> contentLinks, LoaderOptions loaderOptions)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<ContentReference> contentLinks

A list of references to content that should be fetched.

LoaderOptions loaderOptions

The settings that specifies how the content should be loaded, e.g. the language to get the content in.

Returns
Type Description
System.Collections.Generic.IEnumerable<IContent>

A list of content for the specifed references.

Remarks

For references that specifies a specific version (that is where WorkID is set) the language on context is ignored and that specific version is returned.

If contentLinks contain duplicate entries only one IContent instance is returned for the duplicate entries.

GetItems(IEnumerable<ContentReference>, CultureInfo)

Gets all content items that is represented by the provided references given the language.

Declaration
public abstract IEnumerable<IContent> GetItems(IEnumerable<ContentReference> contentLinks, CultureInfo language)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<ContentReference> contentLinks

A list of references to content that should be fetched.

System.Globalization.CultureInfo language

The language.

Returns
Type Description
System.Collections.Generic.IEnumerable<IContent>

A list of content for the specifed references.

Remarks

For references that specifies a specific version (that is where WorkID is set) the language is ignored and that specific version is returned.

If contentLinks contain duplicate entries only one IContent instance is returned for the duplicate entries.

GetLanguageBranches<T>(ContentReference)

Retrieves a collection of IContentData objects for all languages of the provided content link.

Declaration
public abstract IEnumerable<T> GetLanguageBranches<T>(ContentReference contentLink)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

The reference whose language branches you want to retrieve.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

A collection of IContent for all language branches.

Type Parameters
Name Description
T

GetReferencesToContent(ContentReference, Boolean)

Gets the reference information of the references to the specified content and optionally its descendants.

Declaration
public abstract IEnumerable<ReferenceInformation> GetReferencesToContent(ContentReference contentLink, bool includeDecendents)
Parameters
Type Name Description
ContentReference contentLink

The content link.

System.Boolean includeDecendents

if set to true references to descendants are also checked.

Returns
Type Description
System.Collections.Generic.IEnumerable<ReferenceInformation>

ListDelayedPublish()

Lists all content that are set to delayed publish.

Declaration
public abstract IEnumerable<IContent> ListDelayedPublish()
Returns
Type Description
System.Collections.Generic.IEnumerable<IContent>

All matching content Versions

Move(ContentReference, ContentReference, AccessLevel, AccessLevel)

Moves a content from it's current location to another position in the content structure first ensuring that the current user meets the minimal access right requirements.

Declaration
public abstract ContentReference Move(ContentReference contentLink, ContentReference destination, AccessLevel requiredSourceAccess, AccessLevel requiredDestinationAccess)
Parameters
Type Name Description
ContentReference contentLink

The content that should be moved.

ContentReference destination

The destination where the content will be moved as a child to.

AccessLevel requiredSourceAccess

The minimal access rights required on the source content that is to be moved.

AccessLevel requiredDestinationAccess

The minimal access rights required on the destination.

Returns
Type Description
ContentReference

A ContentReference to the moved content.

MoveToWastebasket(ContentReference, String)

Moves a page to the wastebasket.

Declaration
public abstract void MoveToWastebasket(ContentReference contentLink, string deletedBy)
Parameters
Type Name Description
ContentReference contentLink

The content that should be moved to the wastebasket.

System.String deletedBy

The user who deleted the content.

Save(IContent, SaveAction, AccessLevel)

Saves a content to the repository with the provided save action performed first ensuring that the current user meets the minimum access rights requirements.

Declaration
public abstract ContentReference Save(IContent content, SaveAction action, AccessLevel access)
Parameters
Type Name Description
IContent content

An IContent object containing all the data that should be saved.

SaveAction action

The exact SaveAction that should be performed.

AccessLevel access

The minimum access level that the current user must have to the content.

Returns
Type Description
ContentReference

A ContentReference to the saved content.

TryGet<T>(ContentReference, out T)

Gets the content item represented by the provided reference.

Declaration
public abstract bool TryGet<T>(ContentReference contentLink, out T content)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

The link to the content.

T content

The content with given id or null if content not found or if type is not assignable to T.

Returns
Type Description
System.Boolean

True if content is found or false if content is not found or if found content is of a type not assignable to T.

Type Parameters
Name Description
T

The type of content to get.

TryGet<T>(ContentReference, LoaderOptions, out T)

Gets the content item represented by the provided reference.

Declaration
public abstract bool TryGet<T>(ContentReference contentLink, LoaderOptions loaderOptions, out T content)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

The link to the content.

LoaderOptions loaderOptions

The settings that specifies how the content should be loaded, e.g. the language to get the content in.

T content

The content with given id or null if content not found or if type is not assignable to T.

Returns
Type Description
System.Boolean

True if content is found or false if content is not found or if found content is of a type not assignable to T.

Type Parameters
Name Description
T

The type of content to get.

TryGet<T>(ContentReference, CultureInfo, out T)

Gets the content item represented by the provided reference given the language.

Declaration
public abstract bool TryGet<T>(ContentReference contentLink, CultureInfo language, out T content)
    where T : IContentData
Parameters
Type Name Description
ContentReference contentLink

The link to the content.

System.Globalization.CultureInfo language

The language.

T content

The content with given id or null if content not found or if type is not assignable to T.

Returns
Type Description
System.Boolean

True if content is found or false if content is not found or if found content is of a type not assignable to T.

Type Parameters
Name Description
T

The type of content to get.

Remarks

If the contentLink is a specific version (that is where WorkID is set) the language is ignored and that specific version is returned.

TryGet<T>(Guid, out T)

Gets the content item represented by the provided reference.

Declaration
public abstract bool TryGet<T>(Guid contentGuid, out T content)
    where T : IContentData
Parameters
Type Name Description
System.Guid contentGuid

The unique identifier for the content.

T content

The content with given id or null if content not found or if type is not assignable to T.

Returns
Type Description
System.Boolean

True if content is found or false if content is not found or if found content is of a type not assignable to T.

Type Parameters
Name Description
T

The type of content to get.

TryGet<T>(Guid, LoaderOptions, out T)

Gets the content item represented by the provided reference.

Declaration
public abstract bool TryGet<T>(Guid contentGuid, LoaderOptions loaderOptions, out T content)
    where T : IContentData
Parameters
Type Name Description
System.Guid contentGuid

The unique identifier for the content.

LoaderOptions loaderOptions

The settings that specifies how the content should be loaded, e.g. the language to get the content in.

T content

The content with given id or null if content not found or if type is not assignable to T.

Returns
Type Description
System.Boolean

True if content is found or false if content is not found or if found content is of a type not assignable to T.

Type Parameters
Name Description
T

The type of content to get.

TryGet<T>(Guid, CultureInfo, out T)

Gets the content item represented by the provided reference given the language.

Declaration
public abstract bool TryGet<T>(Guid contentTGuid, CultureInfo language, out T content)
    where T : IContentData
Parameters
Type Name Description
System.Guid contentTGuid

The guid to the content.

System.Globalization.CultureInfo language

The language.

T content

The content with given id or null if content not found or if type is not assignable to T.

Returns
Type Description
System.Boolean

True if content is found or false if content is not found or if found content is of a type not assignable to T.

Type Parameters
Name Description
T

The type of content to get.

Implements

Extension Methods