Loading...

All project content is available for reading, but you need to be a member of the project for Subversion checkout of source code, or to create/modify any information.
Login if you are a member. Apply here to request membership (open to all).

EPiCode Extensions

This is an EPiServer World Community project for extension methods we use in our EPiServer projects.

For documentation see: Guide to EPiCode.Extensions

The convention is fairly simple. EPiServer.Extensions.PageDataExtensions contains the extensions for the PageData class, EPiServer.Extensions.PageReference contains the extensions for the PageReference class and so forth. All the classes are partial.

We recommend adding the namespace to your web.config file for easy use:

<pages>
    <namespaces>
        <add namespace="EPiCode.Extensions"/>
    </namespaces>
</pages>

You can also do this in your .aspx/.ascx files:

<%@ Import Namespace="EPiCode.Extensions" %>

CategoryCollectionExtensions class

public static CategoryCollection Select(this CategoryCollection categories, Action<Category> action){..}
public static CategoryCollection Where(this CategoryCollection categories, Func<Category, bool> function){..}
public static CategoryList ToCategoryList(this CategoryCollection categoryCollection){..}

CategoryListExtensions class

For more information: Extending EPiServer Categories

public static CategoryCollection GetActiveSubCategories(this CategoryList allActiveCategoryIds, string parentCategoryName){..}
public static CategoryCollection GetActiveSubCategories(this CategoryList allActiveCategoryIds, int parentCategoryId){..}
public static CategoryCollection GetActiveSubCategories(this CategoryList allActiveCategoryIds, Category parentCategory){..}
public static CategoryCollection ToCategoryCollection (this CategoryList categoryList){..}

ControlExtensions class

public static string RenderToString(this Control control){..}
public static IEnumerable<T> FindChildControls<T>(this Control parentControl, Predicate<Control> predicate) where T : Control{..}
public static bool AddToHeader(this Control control){..}
public static bool AddToParent(this Control control, string path){..}

EnumerableExtensions

public static PageDataCollection ToPageDataCollection (this IEnumerable<PageData> pages){..}
public static PageDataCollection ToPageDataCollection(this IEnumerable<PageReference> pageReferences){..}

LinkItemCollectionExtensions

public static PageDataCollection ToPageDataCollection(this LinkItemCollection linkItemCollection){..}

ObjectExtensions

public static string ToWebString(this object obj){..}
public static string Translate(this object obj, string xpath) {..}

PageDataCollectionExtensions

public static PageDataCollection FilterForVisitor(this PageDataCollection pageDataCollection, bool keepPagesWithoutTemplate){..}
public static PageDataCollection FilterForVisitor(this PageDataCollection pageDataCollection){..}
public static PageDataCollection FilterTemplate(this PageDataCollection pageDataCollection){..}
public static PageDataCollection FilterAccess(this PageDataCollection pageDataCollection, AccessLevel accessLevel){..}
public static PageDataCollection FilterCompareTo(this PageDataCollection pageDataCollection, string propertyName, string propertyValue){..}
public static PageDataCollection FilterCount(this PageDataCollection pageDataCollection, int count){..}
public static PageDataCollection FilterPublished(this PageDataCollection pageDataCollection, PagePublishedStatus pagePublishedStatus){..}
public static PageDataCollection FilterPropertySort(this PageDataCollection pageDataCollection, string propertyName){..}
public static PageDataCollection FilterPropertySort(this PageDataCollection pageDataCollection, string propertyName, FilterSortDirection filterSortDirection){..}
public static PageDataCollection FilterRemoveNullValues(this PageDataCollection pageDataCollection, string propertyName){..}
public static PageDataCollection FilterSkipCount(this PageDataCollection pageDataCollection, int skipCount){..}
public static PageDataCollection FilterSort(this PageDataCollection pageDataCollection, FilterSortOrder sortOrder){..}

PageDataExtensions

public static bool IsValue(this PageData page, string propertyName){..}
public static PropertyData GetProperty(this PageData page, string propertyNames){..}
public static bool IsPublished(this PageData page){..}
public static PageDataCollection GetChildren(this PageData page){..}
public static string GetExternalUrl(this PageData page){..}
public static T PropertyValue<T>(this PageData page, string propertyName){..}
public static T PropertyValueWithDefault<T>(this PageData page, string propertyName, T defaultValue){..}
public static string FormatHtml(this PageData page, string propertyName, string startTag, string endTag){..}

public static string FormatHtml(this PageData page, string propertyName,string format){..}
public static bool IsSelected(this PageData page, PageData currentPage){..}
public static bool IsEPiServerPage(this PageData page) {..}

public static string HtmlImage(this PageData page, string imagePropertyName) {..}
public static string HtmlImage(this PageData page, string imagePropertyName, object attributes) {..}
public static string HtmlImage(this PageData page, string imagePropertyName, string altTextPropertyName) {..}
public static string HtmlImage(this PageData page, string imagePropertyName, string altTextPropertyName, object attributes) {..}
public static string HtmlImage(this PageData page, Func<PageData, string> imagePath) {..}
public static string HtmlImage(this PageData page, Func<PageData, string> imagePath, object attributes) {..}
public static string HtmlImage(this PageData page, Func<PageData, string> imagePath, string altText) {..}
public static string HtmlImage(this PageData page, Func<PageData, string> imagePath, string altText, object attributes) {..}
public static string HtmlImage(this PageData page, Func<PageData, string> imagePath, Func<PageData, string> altText) {..}
public static string HtmlImage(this PageData page, Func<PageData, string> imagePath, Func<PageData, string> altText, object attributes) {..}

public static string HtmlLink(this PageData page){..}
public static string HtmlLink(this PageData page, string linkText){..}
public static string HtmlLink(this PageData page, Func<PageData, string> linkText){..}
public static string HtmlLink(this PageData page, object attributes){..}
public static string HtmlLink(this PageData page, string linkText, object attributes){..}
public static string HtmlLink(this PageData page, Func<PageData, string> linkText, object attributes){..}

public static PageData GetParent(this PageData page){..}
public static IEnumerable<PageData> GetAncestors(this PageData page){..}
public static IEnumerable<PageData> GetAncestors(this PageData page, PageReference rootPage){..}
public static PageData GetAncestorAtLevel(this PageData page, PageReference rootPage, int offset){..}

public static string StripHtml(this PageData page){..}
public static string StripHtml(this PageData page, int maxTextLength){..}
public static string StripHtml(this PageData page, string propertyName){..}
public static string StripHtml(this PageData page, string propertyName, int maxTextLength){..}
public static string StripHtml(this PageData page, Func<PageData, string> htmlText){..}
public static string StripHtml(this PageData page, Func<PageData, string> htmlText, int maxTextLength){..}

public static IEnumerable<PageData> GetDescendants(this PageData rootPage){..}
public static IEnumerable<PageData> GetDescendants(this PageData rootPage, int levels){..}

public static bool HasChildren(this PageData pageData){..}

PageReferenceExtensions

public static bool IsPage(this PageReference pageReference){..}
public static PageData GetPage(this PageReference pageReference){..}
public static PageDataCollection GetChildren(this PageReference pageReference){..}
public static IEnumerable<PageData> GetDescendants(this PageReference rootPageReference){..}
public static IEnumerable<PageData> GetDescendants(this PageReference rootPageReference, int levels){..}
public static string GetExternalUrl(this PageReference pageReference){..}
public static bool IsValue(this PageReference pageReference, string propertyName){..}
public static string LinkURL(this PageReference pageReference){..}

PropertyXhtmlStringExtensions

public static string ToPresentationString(this PropertyXhtmlString propertyData, PageBase page){..}

StringExtensions

public static string ToHtmlEncoded(this string text){..}
public static string ToJavaScriptEncoded(this string text){..}
public static string ToUrlEncoded(this string text){..}
public static string FormatHtml(this string text, string startTag, string endTag){..}
public static string StripHtml(this string htmlText, int? maxTextLength){..}
public static bool IsNullOrEmpty(this string text){..}
public static bool IsNotNullOrEmpty(this string text){..}
public static string HtmlImage(this string imagePath){..}
public static string HtmlImage(this string imagePath, string altText){..}
public static string HtmlImage(this string imagePath, object attributes){..}
public static string HtmlImage(this string imagePath, string altText, object attributes){..}

Download

Release version of EPiCode.Extension - compiled with EPiServer CMS 6

Requirements

  • EPiServer CMS 6 or newer
  • Visual Studio 2010 to compile the code

Support

As all code on EPiCode, use the ticket system or chat channel for support, and as always - use at your own risk.

Version history

  • 1.2.6.0: Fix to make sure external URLs are not rendered as internal URLs (contributed by Dzulqarnain Nasir).
  • 1.2.5.0: Refactored CategoryList and CategoryCollection code. Added new extension method for converting CategoryList to CategoryCollection
  • 1.2.0.0: New extension method: FilterTemplate, filters out pages that don't have a template. Overload method for FilterForVisitor that keeps pages without template
  • 1.1.4.0: Added new extension methods: LinkURL that gets the LinkURL for a PageReference (if null it returns an empty string). Updated GetExternalUrl to include languagebranch (contributed by Joel Williams). New Category extension methods: Select, Where and ToCategoryList (contributed by Adam Jenkin).
  • 1.1.3.4: Added new extension method: IsPage that returns true if the EPiServer page exists, false otherwise. Checks a PageReference object.
  • 1.1.3.3: Added new extension method: ToPageDataCollection for IEnumerable<PageReference>
  • 1.1.3.2: Added two new extension methods FilterPublished() and FilterRemoveNullValues()
  • 1.1.3.1: Bug fix for PropertyValueWithDefault to make it work with dynamic properties and fetch data from

Attachments