Class ContentExtensions
Inheritance
Namespace:System.Dynamic.ExpandoObject
Assembly:Umbraco.Core.dll
Syntax
public static class ContentExtensions
Methods
Ancestors(IContent)
Returns a list of the current contents ancestors, not including the content itself.
Declaration
public static IEnumerable<IContent> Ancestors(this IContent content)
Parameters
Type | Name | Description |
---|---|---|
IContent | content | Current content |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IContent> | An enumerable list of IContent objects |
Ancestors(IMedia)
Returns a list of the current medias ancestors, not including the media itself.
Declaration
public static IEnumerable<IMedia> Ancestors(this IMedia media)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | Current media |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An enumerable list of IMedia objects |
Children(IContent)
Returns a list of the current contents children.
Declaration
public static IEnumerable<IContent> Children(this IContent content)
Parameters
Type | Name | Description |
---|---|---|
IContent | content | Current content |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IContent> | An enumerable list of IContent objects |
Children(IMedia)
Returns a list of the current medias children.
Declaration
public static IEnumerable<IMedia> Children(this IMedia media)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | Current media |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An enumerable list of IMedia objects |
Descendants(IContent)
Returns a list of the current contents descendants, not including the content itself.
Declaration
public static IEnumerable<IContent> Descendants(this IContent content)
Parameters
Type | Name | Description |
---|---|---|
IContent | content | Current content |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IContent> | An enumerable list of IContent objects |
Descendants(IMedia)
Returns a list of the current medias descendants, not including the media itself.
Declaration
public static IEnumerable<IMedia> Descendants(this IMedia media)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | Current media |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An enumerable list of IMedia objects |
GetContentType(IContentBase)
Declaration
public static IContentTypeComposition GetContentType(this IContentBase contentBase)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | contentBase |
Returns
Type | Description |
---|---|
IContentTypeComposition |
GetCreatorProfile(IContentBase)
Gets the IProfile for the Creator of this content item.
Declaration
[Obsolete("Use the overload that declares the IUserService to use")]
public static IProfile GetCreatorProfile(this IContentBase content)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content |
Returns
Type | Description |
---|---|
IProfile |
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)
Gets the IProfile for the Creator of this media item.
Declaration
[Obsolete("Use the overload that declares the IUserService to use")]
public static IProfile GetCreatorProfile(this IMedia media)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media |
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)
Returns a list of all dirty user defined properties
Declaration
public static IEnumerable<string> GetDirtyUserProperties(this IContentBase entity)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | entity |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.String> |
GetNonGroupedProperties(IContentBase)
Returns properties that do not belong to a group
Declaration
public static IEnumerable<Property> GetNonGroupedProperties(this IContentBase content)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Property> |
GetPropertiesForGroup(IContentBase, PropertyGroup)
Returns the Property object for the given property group
Declaration
public static IEnumerable<Property> GetPropertiesForGroup(this IContentBase content, PropertyGroup propertyGroup)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content | |
PropertyGroup | propertyGroup |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Property> |
GetWriterProfile(IContent)
Gets the IProfile for the Writer of this content.
Declaration
[Obsolete("Use the overload that declares the IUserService to use")]
public static IProfile GetWriterProfile(this IContent content)
Parameters
Type | Name | Description |
---|---|---|
IContent | content |
Returns
Type | Description |
---|---|
IProfile |
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 |
HasPublishedVersion(IContent)
Checks whether an IContent item has any published versions
Declaration
[Obsolete("Use the HasPublishedVersion property.", false)]
public static bool HasPublishedVersion(this IContent content)
Parameters
Type | Name | Description |
---|---|---|
IContent | content |
Returns
Type | Description |
---|---|
System.Boolean | True if the content has any published versiom otherwise False |
IsAnyUserPropertyDirty(IContentBase)
Declaration
public static bool IsAnyUserPropertyDirty(this IContentBase entity)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | entity |
Returns
Type | Description |
---|---|
System.Boolean |
Parent(IContent)
Returns the parent of the current content.
Declaration
public static IContent Parent(this IContent content)
Parameters
Type | Name | Description |
---|---|---|
IContent | content | Current content |
Returns
Type | Description |
---|---|
IContent | An IContent object |
Parent(IMedia)
Returns the parent of the current media.
Declaration
public static IMedia Parent(this IMedia media)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | Current media |
Returns
Type | Description |
---|---|
IMedia | An IMedia object |
PropertyValues(IContentBase, Object)
Set property values by alias with an annonymous object
Declaration
public static void PropertyValues(this IContentBase content, object value)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content | |
System.Object | value |
RemoveTags(IContentBase, String, IEnumerable<String>, String)
Remove any of the tags specified in the collection from the property if they are currently assigned.
Declaration
public static void RemoveTags(this IContentBase content, string propertyTypeAlias, IEnumerable<string> tags, string tagGroup = "default")
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content | |
System.String | propertyTypeAlias | |
System.Collections.Generic.IEnumerable<System.String> | tags | |
System.String | tagGroup | The group/category that the tags are currently assigned to, the default value is "default" |
SanitizeEntityPropertiesForXmlStorage(IContentBase)
Removes characters that are not valide 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.
SetTags(IContentBase, String, IEnumerable<String>, Boolean, String)
Sets tags for the property - will add tags to the tags table and set the property value to be the comma delimited value of the tags.
Declaration
public static void SetTags(this IContentBase content, string propertyTypeAlias, IEnumerable<string> tags, bool replaceTags, string tagGroup = "default")
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content | The content item to assign the tags to |
System.String | propertyTypeAlias | The property alias to assign the tags to |
System.Collections.Generic.IEnumerable<System.String> | tags | The tags to assign |
System.Boolean | replaceTags | True to replace the tags on the current property with the tags specified or false to merge them with the currently assigned ones |
System.String | tagGroup | The group/category to assign the tags, the default value is "default" |
SetTags(IContentBase, TagCacheStorageType, String, IEnumerable<String>, Boolean, String)
Sets tags for the property - will add tags to the tags table and set the property value to be the comma delimited value of the tags.
Declaration
public static void SetTags(this IContentBase content, TagCacheStorageType storageType, string propertyTypeAlias, IEnumerable<string> tags, bool replaceTags, string tagGroup = "default")
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content | The content item to assign the tags to |
TagCacheStorageType | storageType | The tag storage type in cache (default is csv) |
System.String | propertyTypeAlias | The property alias to assign the tags to |
System.Collections.Generic.IEnumerable<System.String> | tags | The tags to assign |
System.Boolean | replaceTags | True to replace the tags on the current property with the tags specified or false to merge them with the currently assigned ones |
System.String | tagGroup | The group/category to assign the tags, the default value is "default" |
SetValue(IContentBase, String, String, Stream)
Stores and sets a file as a property value.
Declaration
public static void SetValue(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content | IContentBaseA content item. |
System.String | propertyTypeAlias | The property alias. |
System.String | filename | The name of the file. |
System.IO.Stream | filestream | A stream containing the file data. |
Remarks
This really is for FileUpload fields only, and should be obsoleted. For anything else, you need to store the file by yourself using Store and then figure out how to deal with auto-fill properties (if any) and thumbnails (if any) by yourself.
SetValue(IContentBase, String, HttpPostedFile)
Stores and sets an uploaded HttpPostedFile as a property value.
Declaration
public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFile value)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content | IContentBaseA content item. |
System.String | propertyTypeAlias | The property alias. |
System.Web.HttpPostedFile | value | The uploaded System.Web.HttpPostedFile. |
SetValue(IContentBase, String, HttpPostedFileBase)
Stores and sets an uploaded HttpPostedFileBase as a property value.
Declaration
public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFileBase value)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content | IContentBaseA content item. |
System.String | propertyTypeAlias | The property alias. |
System.Web.HttpPostedFileBase | value | The uploaded System.Web.HttpPostedFileBase. |
SetValue(IContentBase, String, HttpPostedFileWrapper)
Stores and sets an uploaded HttpPostedFileWrapper as a property value.
Declaration
[Obsolete("There is no reason for this overload since HttpPostedFileWrapper inherits from HttpPostedFileBase")]
public static void SetValue(this IContentBase content, string propertyTypeAlias, HttpPostedFileWrapper value)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content | IContentBaseA content item. |
System.String | propertyTypeAlias | The property alias. |
System.Web.HttpPostedFileWrapper | value | The uploaded System.Web.HttpPostedFileWrapper. |
StoreFile(IContentBase, String, String, Stream, String)
Stores a file.
Declaration
public static string StoreFile(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream, string filepath)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | content | IContentBaseA content item. |
System.String | propertyTypeAlias | The property alias. |
System.String | filename | The name of the file. |
System.IO.Stream | filestream | A stream containing the file data. |
System.String | filepath | The original file path, if any. |
Returns
Type | Description |
---|---|
System.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.
ToXml(IContent)
Creates the xml representation for the IContent object
Declaration
[Obsolete("Use the overload that declares the IPackagingService to use")]
public static XElement ToXml(this IContent content)
Parameters
Type | Name | Description |
---|---|---|
IContent | content | IContent to generate xml for |
Returns
Type | Description |
---|---|
System.Xml.Linq.XElement | Xml representation of the passed in IContent |
ToXml(IContent, Boolean)
Creates the xml representation for the IContent object
Declaration
[Obsolete("Use the overload that declares the IPackagingService to use")]
public static XElement ToXml(this IContent content, bool isPreview)
Parameters
Type | Name | Description |
---|---|---|
IContent | content | IContent to generate xml for |
System.Boolean | isPreview | Boolean indicating whether the xml should be generated for preview |
Returns
Type | Description |
---|---|
System.Xml.Linq.XElement | Xml representation of the passed in IContent |
ToXml(IContent, IPackagingService)
Creates the xml representation for the IContent object
Declaration
public static XElement ToXml(this IContent content, IPackagingService packagingService)
Parameters
Type | Name | Description |
---|---|---|
IContent | content | IContent to generate xml for |
IPackagingService | packagingService |
Returns
Type | Description |
---|---|
System.Xml.Linq.XElement | Xml representation of the passed in IContent |
ToXml(IContent, IPackagingService, Boolean)
Creates the xml representation for the IContent object
Declaration
public static XElement ToXml(this IContent content, IPackagingService packagingService, bool isPreview)
Parameters
Type | Name | Description |
---|---|---|
IContent | content | IContent to generate xml for |
IPackagingService | packagingService | |
System.Boolean | isPreview | Boolean indicating whether the xml should be generated for preview |
Returns
Type | Description |
---|---|
System.Xml.Linq.XElement | Xml representation of the passed in IContent |
ToXml(IMedia)
Creates the xml representation for the IMedia object
Declaration
[Obsolete("Use the overload that declares the IPackagingService to use")]
public static XElement ToXml(this IMedia media)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | IContent to generate xml for |
Returns
Type | Description |
---|---|
System.Xml.Linq.XElement | Xml representation of the passed in IContent |
ToXml(IMedia, IPackagingService)
Creates the xml representation for the IMedia object
Declaration
public static XElement ToXml(this IMedia media, IPackagingService packagingService)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | IContent to generate xml for |
IPackagingService | packagingService |
Returns
Type | Description |
---|---|
System.Xml.Linq.XElement | Xml representation of the passed in IContent |
ToXml(IMember)
Creates the xml representation for the IMember object
Declaration
[Obsolete("Use the overload that declares the IPackagingService to use")]
public static XElement ToXml(this IMember member)
Parameters
Type | Name | Description |
---|---|---|
IMember | member | IMember to generate xml for |
Returns
Type | Description |
---|---|
System.Xml.Linq.XElement | Xml representation of the passed in IContent |
ToXml(IMember, IPackagingService)
Creates the xml representation for the IMember object
Declaration
public static XElement ToXml(this IMember member, IPackagingService packagingService)
Parameters
Type | Name | Description |
---|---|---|
IMember | member | IMember to generate xml for |
IPackagingService | packagingService |
Returns
Type | Description |
---|---|
System.Xml.Linq.XElement | Xml representation of the passed in IContent |
WasAnyUserPropertyDirty(IContentBase)
Declaration
public static bool WasAnyUserPropertyDirty(this IContentBase entity)
Parameters
Type | Name | Description |
---|---|---|
IContentBase | entity |
Returns
Type | Description |
---|---|
System.Boolean |