Class ContentExtensions
Provides extension methods for IContentBase, IContent, and IMedia types.
Inheritance
Namespace: Umbraco.Extensions
Assembly: Umbraco.Core.dll
Syntax
public static class ContentExtensions
Methods
View SourceGetAncestorIds(IContent)
Gets a collection containing the ids of all ancestors.
Declaration
public static IEnumerable<int>? GetAncestorIds(this IContent content)
Parameters
| Type | Name | Description |
|---|---|---|
| IContent | content | IContent to retrieve ancestors for |
Returns
| Type | Description |
|---|---|
| IEnumerable<int> | An Enumerable list of integer ids |
GetCreatorProfile(IContentBase, IUserService)
Gets the IProfile for the Creator of this content item.
Declaration
public static IProfile? GetCreatorProfile(this IContentBase content, IUserService userService)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | content | |
| IUserService | userService |
Returns
| Type | Description |
|---|---|
| IProfile |
GetCreatorProfile(IMedia, IUserService)
Gets the IProfile for the Creator of this media item.
Declaration
public static IProfile? GetCreatorProfile(this IMedia media, IUserService userService)
Parameters
| Type | Name | Description |
|---|---|---|
| IMedia | media | |
| IUserService | userService |
Returns
| Type | Description |
|---|---|
| IProfile |
GetDirtyUserProperties(IContentBase)
Gets the aliases of all dirty (modified) user properties.
Declaration
public static IEnumerable<string> GetDirtyUserProperties(this IContentBase entity)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | entity | The content entity. |
Returns
| Type | Description |
|---|---|
| IEnumerable<string> | A collection of property aliases that are dirty. |
GetNonGroupedProperties(IContentBase)
Returns properties that do not belong to a group
Declaration
public static IEnumerable<IProperty> GetNonGroupedProperties(this IContentBase content)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | content |
Returns
| Type | Description |
|---|---|
| IEnumerable<IProperty> |
GetPropertiesByEditor(IContentBase, string)
Returns all properties based on the editorAlias
Declaration
public static IEnumerable<IProperty> GetPropertiesByEditor(this IContentBase content, string editorAlias)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | content | |
| string | editorAlias |
Returns
| Type | Description |
|---|---|
| IEnumerable<IProperty> |
GetPropertiesForGroup(IContentBase, PropertyGroup)
Returns the Property object for the given property group
Declaration
public static IEnumerable<IProperty> GetPropertiesForGroup(this IContentBase content, PropertyGroup propertyGroup)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | content | |
| PropertyGroup | propertyGroup |
Returns
| Type | Description |
|---|---|
| IEnumerable<IProperty> |
GetStatus(IContent, ContentScheduleCollection, string?)
Gets the current status of the Content
Declaration
public static ContentStatus GetStatus(this IContent content, ContentScheduleCollection contentSchedule, string? culture = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IContent | content | |
| ContentScheduleCollection | contentSchedule | |
| string | culture |
Returns
| Type | Description |
|---|---|
| ContentStatus |
GetWriterProfile(IContent, IUserService)
Gets the IProfile for the Writer of this content.
Declaration
public static IProfile? GetWriterProfile(this IContent content, IUserService userService)
Parameters
| Type | Name | Description |
|---|---|---|
| IContent | content | |
| IUserService | userService |
Returns
| Type | Description |
|---|---|
| IProfile |
GetWriterProfile(IMedia, IUserService)
Gets the IProfile for the Writer of this content.
Declaration
public static IProfile? GetWriterProfile(this IMedia content, IUserService userService)
Parameters
| Type | Name | Description |
|---|---|---|
| IMedia | content | |
| IUserService | userService |
Returns
| Type | Description |
|---|---|
| IProfile |
IsAnyUserPropertyDirty(IContentBase)
Determines whether any user property of the content base is dirty (has been modified).
Declaration
public static bool IsAnyUserPropertyDirty(this IContentBase entity)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | entity | The content entity to check. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsMoving(IContentBase)
Determines whether the content entity is being moved as part of a bulk move operation.
Declaration
public static bool IsMoving(this IContentBase entity)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | entity | The content entity to check. |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
When moving, only Path, Level, and UpdateDate properties are changed. This allows bypassing version creation operations since the move cannot be rolled back.
SanitizeEntityPropertiesForXmlStorage(IContentBase)
Removes characters that are not valid XML characters from all entity properties of type string. See: http://stackoverflow.com/a/961504/5018
Declaration
public static void SanitizeEntityPropertiesForXmlStorage(this IContentBase entity)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | entity |
Remarks
If this is not done then the xml cache can get corrupt and it will throw YSODs upon reading it.
SetValue(IContentBase, MediaFileManager, MediaUrlGeneratorCollection, IShortStringHelper, IContentTypeBaseServiceProvider, string, string, Stream, string?, string?)
Sets the posted file value of a property.
Declaration
public static void SetValue(this IContentBase content, MediaFileManager mediaFileManager, MediaUrlGeneratorCollection mediaUrlGenerators, IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string? culture = null, string? segment = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | content | |
| MediaFileManager | mediaFileManager | |
| MediaUrlGeneratorCollection | mediaUrlGenerators | |
| IShortStringHelper | shortStringHelper | |
| IContentTypeBaseServiceProvider | contentTypeBaseServiceProvider | |
| string | propertyTypeAlias | |
| string | filename | |
| Stream | filestream | |
| string | culture | |
| string | segment |
StoreFile(IContentBase, MediaFileManager, IContentTypeBaseServiceProvider, string, string, Stream, string)
Stores a file.
Declaration
public static string StoreFile(this IContentBase content, MediaFileManager mediaFileManager, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string filepath)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | content | IContentBaseA content item. |
| MediaFileManager | mediaFileManager | The media file manager. |
| IContentTypeBaseServiceProvider | contentTypeBaseServiceProvider | The content type base service provider. |
| string | propertyTypeAlias | The property alias. |
| string | filename | The name of the file. |
| Stream | filestream | A stream containing the file data. |
| string | filepath | The original file path, if any. |
Returns
| Type | Description |
|---|---|
| string | The path to the file, relative to the media filesystem. |
Remarks
Does NOT set the property value, so one should probably store the file and then do something alike: property.Value = MediaHelper.FileSystem.GetUrl(filepath).
The original file path is used, in the old media file path scheme, to try and reuse the "folder number" that was assigned to the previous file referenced by the property, if any.
ToDeepXml(IContent, IEntityXmlSerializer)
Creates the full xml representation for the IContent object and all of it's descendants
Declaration
public static XElement ToDeepXml(this IContent content, IEntityXmlSerializer serializer)
Parameters
| Type | Name | Description |
|---|---|---|
| IContent | content | IContent to generate xml for |
| IEntityXmlSerializer | serializer |
Returns
| Type | Description |
|---|---|
| XElement | Xml representation of the passed in IContent |
ToXml(IContent, IEntityXmlSerializer)
Creates the xml representation for the IContent object
Declaration
public static XElement ToXml(this IContent content, IEntityXmlSerializer serializer)
Parameters
| Type | Name | Description |
|---|---|---|
| IContent | content | IContent to generate xml for |
| IEntityXmlSerializer | serializer |
Returns
| Type | Description |
|---|---|
| XElement | Xml representation of the passed in IContent |
ToXml(IMedia, IEntityXmlSerializer)
Creates the xml representation for the IMedia object
Declaration
public static XElement ToXml(this IMedia media, IEntityXmlSerializer serializer)
Parameters
| Type | Name | Description |
|---|---|---|
| IMedia | media | IContent to generate xml for |
| IEntityXmlSerializer | serializer |
Returns
| Type | Description |
|---|---|
| XElement | Xml representation of the passed in IContent |
ToXml(IMember, IEntityXmlSerializer)
Creates the xml representation for the IMember object
Declaration
public static XElement ToXml(this IMember member, IEntityXmlSerializer serializer)
Parameters
| Type | Name | Description |
|---|---|---|
| IMember | member | IMember to generate xml for |
| IEntityXmlSerializer | serializer |
Returns
| Type | Description |
|---|---|
| XElement | Xml representation of the passed in IContent |
TryGetMediaPath(IContentBase, string, MediaUrlGeneratorCollection, out string?, string?, string?)
Returns the path to a media item stored in a property if the property editor is IMediaUrlGenerator
Declaration
public static bool TryGetMediaPath(this IContentBase content, string propertyTypeAlias, MediaUrlGeneratorCollection mediaUrlGenerators, out string? mediaFilePath, string? culture = null, string? segment = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | content | |
| string | propertyTypeAlias | |
| MediaUrlGeneratorCollection | mediaUrlGenerators | |
| string | mediaFilePath | |
| string | culture | |
| string | segment |
Returns
| Type | Description |
|---|---|
| bool | True if the file path can be resolved and the property is IMediaUrlGenerator |
WasAnyUserPropertyDirty(IContentBase)
Determines whether any user property of the content base was dirty (was modified before the last save).
Declaration
public static bool WasAnyUserPropertyDirty(this IContentBase entity)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | entity | The content entity to check. |
Returns
| Type | Description |
|---|---|
| bool |
|