Preserving Rich Text Formatting in non edit-in-place scenario's


SharePoint 2007 allows content editors to edit the web content using either the in place editing or the Edit Forms knows from WSS List Items. Many of the content editors prefer the in place editing mode as it’s more intuitive and user friendly.

While editing rich content in SharePoint 2007 you have two options: you can either use the standard Rich Text Editor (RTE) or the one provided by Telerik. While the SharePoint RTE is far from perfect it is just enough in many situations: it allows you to do the basic formatting, insert pictures and insert tables including formatting using predefined styles.

As long as you use the edit in-place concept you won’t notice anything strange about the behavior of the RTE: your output will (most of the time) match your input. However there are many scenario’s when you will create a separate Edit Panel on the Page Layout where editors will do the editing and you will display the content using either the standard SharePoint:FieldValue control or with your own. (one of the reasons would be the need to strip the first part of the URL in the references to images for example). That’s when things get messy.

Looking at the OnLoad method of the RichHtmlField you will find out that it loads two CSS files: HtmlEditorTableFormats.css and HtmlEditorCustomStyles.css. These files contain respectively the predefined styles for tables formatting and custom CSS styles.

In order to keep the formatting without using the RichHtmlField for content display purposes you have to either register these CSS files from your custom control:

CssRegistration.Register("HtmlEditorTableFormats.css");
CssRegistration.Register("HtmlEditorCustomStyles.css");

or refer to them in the Master Page:

<SharePoint:CssRegistration name="HtmlEditorTableFormats.css"
runat="server"/>
<SharePoint:CssRegistration name="HtmlEditorCustomStyles.css"
runat="server"/>

Technorati Tags: SharePoint, SharePoint 2007, MOSS 2007, WCM

Others found also helpful: