Try our conversational search powered by Generative AI!

Class ContentAssetHelper

Helper class used when working with assets.

Inheritance
System.Object
ContentAssetHelper
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Core
Assembly: EPiServer.dll
Version: 7.19.2
Syntax
public class ContentAssetHelper

Constructors

ContentAssetHelper(IContentRepository, IContentTypeRepository, LanguageSelectorFactory, IPermanentLinkMapper, ContentMediaResolver)

Initializes a new instance of the ContentAssetHelper class.

Declaration
public ContentAssetHelper(IContentRepository contentRepository, IContentTypeRepository contentTypeRepository, LanguageSelectorFactory languageSelectorFactory, IPermanentLinkMapper permanentLinkMapper, ContentMediaResolver mediaResolver)
Parameters
Type Name Description
IContentRepository contentRepository

The content repository.

IContentTypeRepository contentTypeRepository

The content type repository.

LanguageSelectorFactory languageSelectorFactory

The language selector factory.

IPermanentLinkMapper permanentLinkMapper

The permanent link mapper.

ContentMediaResolver mediaResolver

The media resolver.

Methods

GetAssetFolder(ContentReference)

Gets the asset folder for a content item

Declaration
public virtual ContentAssetFolder GetAssetFolder(ContentReference contentLink)
Parameters
Type Name Description
ContentReference contentLink

The content to get asset folder for.

Returns
Type Description
ContentAssetFolder

The asset folder or null if asset folder is not supported because the content item does not implement IResourceable

Exceptions
Type Condition
EPiServerException

Thrown when the content cannot be found

System.ArgumentNullException

When contentLink is null or empty

GetAssetOwner(ContentReference)

Gets the owner for a content item (assuming the content is an asset inside the asset folder)

Declaration
public virtual IContent GetAssetOwner(ContentReference contentLink)
Parameters
Type Name Description
ContentReference contentLink

The content to get asset folder for.

Returns
Type Description
IContent

The asset folder or null if asset folder is not a parent of this content item

Exceptions
Type Condition
EPiServerException

Thrown when the content cannot be found

System.ArgumentNullException

When contentLink is null or empty

GetMedia(ContentReference, String, Guid)

Gets a media item given parent and name and guid based id.

Declaration
protected virtual IContentMedia GetMedia(ContentReference parentLink, string mediaName, Guid mediaId)
Parameters
Type Name Description
ContentReference parentLink

The parent link.

System.String mediaName

Name of the media.

System.Guid mediaId

The media id.

Returns
Type Description
IContentMedia
Remarks

If the media exist it is returned, otherwise a new media item is created (but not saved)

Exceptions
Type Condition
System.ArgumentException

mediaName must contain a valid extension

GetOrCreateAssetFolder(ContentReference)

Gets or cretates the asset folder for a content item

Declaration
public virtual ContentAssetFolder GetOrCreateAssetFolder(ContentReference contentLink)
Parameters
Type Name Description
ContentReference contentLink

The content to get or create asset folder for.

Returns
Type Description
ContentAssetFolder

The asset folder or null if asset folder is not supported because the content item does not implement IResourceable

Remarks

If the passed in content does not have an asset folder one is created.

Exceptions
Type Condition
EPiServerException

Thrown when the content cannot be found

System.ArgumentNullException

When contentLink is null or empty

GetParentFolder(ContentReference, String, Nullable<DateTime>, Boolean)

Gets the parent folder.

Declaration
protected virtual IContent GetParentFolder(ContentReference root, string relativePath, DateTime? saveTime, bool createIfNotExist)
Parameters
Type Name Description
ContentReference root

The root.

System.String relativePath

The relative path.

System.Nullable<System.DateTime> saveTime

The create time.

System.Boolean createIfNotExist

if set to true it will create folder if it does not exist.

Returns
Type Description
IContent
Remarks

This member supports the EPiServer infrastructure and is not intended to be used directly from your code.

WriteProperty(IContent, String, String, Boolean)

Writes the property to a content item.

Declaration
protected virtual void WriteProperty(IContent content, string propertyName, string propertyValue, bool log)
Parameters
Type Name Description
IContent content

The content.

System.String propertyName

Name of the property.

System.String propertyValue

The property value.

System.Boolean log

if set to true [log].

Remarks

If the property has a backing PropertyData instance, ParseToSelf on that instance is called. If there is no backing property data the value is set through reflection and using System.Convert.ChangeType to get correct type from string representation.

Extension Methods