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

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: 10.10.4
Syntax
public abstract class ContentAssetHelper

Constructors

ContentAssetHelper()

Declaration
protected ContentAssetHelper()

Methods

GetAssetFolder(ContentReference)

Gets the asset folder for a content item

Declaration
public abstract 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 abstract 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
public abstract 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 creates the asset folder for a content item

Declaration
public abstract 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
public abstract 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

WriteProperty(IContent, String, String, Boolean)

Writes the property to a content item.

Declaration
public abstract 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