MOSS 2007 RichImageField
RichImageField is rendered as html-tags and external links are not applied to the image correctly. Out of the box, RichImageField may render as visible html-kode instead of a valid image-tag. This I fixed using the solution provided here.
But, external links are not applied correctly. Therefore I have altered the above solution to correct externallinks using a regular expression:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
using System.Web.UI;
using Microsoft.SharePoint.Publishing.WebControls;
namespace Internet.FieldControls
{
public class CustomImageField : RichImageField
{
private const string strRegexLink = "(<a href=\")(?:<a(?:.|\n)*?>)([^<]*)(?:</a>)(\"(?:.|\n)*?>)";
protected override void RenderFieldForDisplay(System.Web.UI.HtmlTextWriter output)
{
Regex regularExpression = new Regex(strRegexLink, RegexOptions.IgnoreCase | RegexOptions.Multiline);
TextWriter textWriter = new StringWriter();
base.RenderFieldForDisplay(new HtmlTextWriter(textWriter));
string fieldHtml = HttpUtility.HtmlDecode(textWriter.ToString());
if (regularExpression.IsMatch(fieldHtml))
fieldHtml = regularExpression.Replace(fieldHtml,"$1$2$3");
output.Write(fieldHtml);
}
}
}
Sidst opdateret: 16. dec. 2016