RichImageField HTML-Encoded in Display Mode

If we use the UI (Site Actions > Site Settings > Modify All Site Settings), we can successfully add a new column to Site Columns to hold an Image. However, if we use a feature to add the Site Column for an image, the HTML for the image is encoded in display mode and shows up as <img … /> instead of the graphic image. What is wrong with the following Feature Site Column definition?

<Field
ID="{6E9A9B81-4325-4b1d-9BEA-9C8001712E4B}"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
Name="CustomImage"
StaticName="CustomImage"
DisplayName="Custom Image"
Group="Custom Page Layout Columns"
Type="Image"
RichText="True"
RichTextMode="FullHtml"/>

[925 byte] By [DanVignieri] at [2007-12-30]
# 1

I had the same problem but found inspiration to a solution in Stefan Go?ner’s blog http://blogs.technet.com/stefan_gossner/archive/2007/03/29/how-to-overcome-glitches-with-the-standard-field-controls-shipped-with-moss-2007.aspx

In his blog he overrides the RenderFieldForDisplay function of the standard RichImageField webpart, so I grabbed his code, changed it a bit and now my Image is showing in display mode. Here is the result:

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls.WebParts;

using System.Security.Permissions;

using System.Xml.Serialization;

using System.Runtime.InteropServices;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

using Microsoft.SharePoint.Publishing.WebControls;

using Microsoft.SharePoint.WebPartPages;

namespace YourNamespace.WebParts.Controls

{

[Guid("50abd899-9a7f-4c54-81f8-e6bcc5fa70cc"),

AspNetHostingPermission(SecurityAction.Demand,

Level = AspNetHostingPermissionLevel.Minimal),

AspNetHostingPermission(SecurityAction.InheritanceDemand,

Level = AspNetHostingPermissionLevel.Minimal)]

public class CustomRichImageField : RichImageField

{

protected override void RenderFieldForDisplay(HtmlTextWriter output)

{

// create a new tempWriter to consume the output from the base class

TextWriter tempWriter = new StringWriter();

base.RenderFieldForDisplay(new HtmlTextWriter(tempWriter));

// capture the output of the base class and do the required adjustments

//string newHtml = tempWriter.ToString().Replace("&gt;", "/ >");

string newHtml = System.Web.HttpUtility.HtmlDecode(tempWriter.ToString()); // This did the job!!

// write out the corrected html

output.Write(newHtml);

}

}

}

GideonCullum at 2007-9-5 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...

SharePoint Products and Technologies

Site Classified