We recently had a small problem with the sample image HTML custom property that is available from the EPiServer site. The property itself works fine and can be quite useful, however the issue we discovered occurs when you import or content mirror pages using this property. In fact, this too is over simplifying the issue, again the property itself works fine unless, and here is the rub, you are linking to an image that exists within a specific page folder, when this situation occurs the image is not imported and the link (src of the image within the HTML tag) is left looking the page folder id from the source site.
The issue
The problem relates to how the property data is stored and what EPiServer does with document links during content shipping. We referred this issue to EPiServer and they had the following to say.
“We do a check on all properties of the type string to see if we should do a replace (the built in URL properties inherit from PropertyString). The values are updated if the link refers to a document on the local site and if the link is to a document on another site we must leave it alone. So we check for links that are relative and not absolute. And to do that we see if the property value starts with a “/”.”
Unfortunately in this instance the property data is a complete HTML image tag I.e. <img xsrc=… and therefore the system does not find the content to update it. So basically, since the property doesn’t start with a “/”, no replacement is done.
The fix
There are a couple of potential fixes to this issue, one would be to handle the events associated with importing and exporting pages and address the text parsing ourselves (refer to the DataImporter and DataExporter classes in the SDK), the other is much simpler and involves changing the base class the custom property inherits from. By using changing the code to inherit from PropertyString to PropertyLongString the mirroring is able to handle the content shipping appropriately.
I opted to address the problem by changing the base class, the advantages that I could see are that
- The problem is fixed once and for all
- No additional effort is required by the system during a content mirroring process
- The fix requires the least effort
The issue with changing the base class from PropertyString to PropertyLongString is that, among other things, it changes the column in the database that the property retrieves its content from, this means that any previously published content would become inaccessible and, with over 10,000 published pages in the customers solution, this posed a bit of a problem. The solution here was to programmatically create a new custom property type (rather then changing the existing) and writing a tool to create a matching property on each affected page type, copy the data from the old property to the new, and then republishing the pages. If there is no content in the system then this step becomes unnecessary.
Note: to get the layout correct when using the PropertyLongString base class, i.e. with the entry textbox to the right of the label you need to add the following to your custom property
public override TableRowLayout RowLayout
{
get
{
return TableRowLayout.Default;
}
}
The technologies explained
Page Folders - Each page within EPiServer can have a “Page Folder” associated with it, a page folder can only be associated with the one page and is a good way of storing files that are uniquely linked to the page content. A specific advantage of a page folder is that when a page is deleted EPiServer provides the site administrator with tools to “tidy up” or delete the now redundant page folders, this means that the upload directory does not end up full of files that are no longer relevant to the current site content.
PropertyString - This is a base content type that stores the property value as a string - rocket science huh
PropertyLongString - Another base content type that stores the property as a string but supports much more content and is normally associated with rich text editing and therefore stores HTML content. While the HTML Image property is not of significant length, by using this property type the system is able to parse the HTML image tag and update the link appropriately.
Content Mirroring - This is a relatively new feature to EPiServer (well since version 4.50) and allows for the shipping of content from one EPiServer installation to another. A common application for this would be sharing content between an Internet and Intranet site, or having an authoring server using integrated authentication shipping content to a read only publishing server in the DMZ.
Rss Feed