Locking down RichHtmlField styles in SharePoint
I read a useful article from alspeirs on how to restrict the content that people can put into editable pages on SharePoint. It is great to see this functionality exposed, as often you need to allow people to enter some html formatting but want to restrict them from breaking a site’s design by entering fonts or tables or other html elements.
To lockdown the styles you set the properties of a RichHtmlField to allow/remove the elements as you see fit. For example to turn off tables images and fonts you would use the following:
<div>
<PublishingWebControls:RichHtmlField
FieldName="PublishingPageContent"
AllowTables="false"
AllowImages="false"
AllowFonts="false"
runat="server"></PublishingWebControls:RichHtmlField>
</div>
This now disables the specified icons on the toolbar, and prevents the user from saving content that contains the restricted elements.
MSDN contains a full list of stuff you can customise.
Another question is – as default if you copy/paste from word into the RTF the formatting is retained. What happens to this embedded style from word if you've disabled the toolabr items or the custom styles??
Also, how/where can you get to the default styles and change those?
Andy Goodwin
29 Jan 09 at 3:04 pm
When you specify AllowFonts="False" in the RichHtmlField control, you will notice that two toolbar items are disabled (Font family & Font size). In the toolbar you will also notice Bold, Italicize, and Underline are all NOT disabled. If you attempt to use one of these functions, the text will be formatted, but once you move away from the text the text is stripped of it's formatting. Why? I only want to disallow the font color and size… Any help on this???
Steve Walsh
2 Oct 07 at 9:48 pm
Ahh found a solution.
set
DisableCustomStyles = "true"
Robert
15 Aug 07 at 12:32 pm
What file do you have to edit toimplement this solution?
Harry Hill
10 Mar 10 at 11:19 am
@Harry Hill – this would normally be in a publishing Page Layout stored in the masterpage gallery. If you have a look at the pages library for the page that shows this control it should also contain a link to the page layout it is using. You can edit these using SharePoint designer or (ideally) create your own page layouts and deploy these using the feature framework. See http://msdn.microsoft.com/en-us/library/ms543497.aspx for more information on page layouts.
Ari Bakker
10 Mar 10 at 5:17 pm
[…] werden. Was man alles deaktivieren kann, ist bei MSDN dokumentiert, wie es geht kann man hier nachlesen ( der Artikel ist zwar für SharePoint 2007, funktioniert aber auch in SharePoint 2010 […]
SharePoint Pages – Best Practices | knauhow
17 Jun 15 at 8:52 pm