views:

541

answers:

2

In SharePoint we have the the richhtmlfield that allows the user to edit the html content of the page. How can I change the css that is applied when they select H1, H2, Normal etc. from the paragraph formatting button?

I would also like to change the css applied to the tables added to the richhtmlfield, is this possible?

All the best

+2  A: 

Is this a MOSS or WSS site collection that we're talking about? If it's MOSS you can just apply an alternate style sheet that will override the default styling. We put it in a folder in the Style Library in the root of the site collection and specified the the URL to be /Style Library/custom/ourStyles.css.

To get to that setting, from the root of the site collection, go to Site Actions->Site Settings->Modify All Site Settings, then click the Master Page link under the Look and Feel column. The setting you're looking for is at the bottom of the page.

The one gotcha we ran into this approach is that we had to edit the Style Library's permissions so that all users had read access. Otherwise, they didn't see the custom styles, even though those of us who were editing them did.

You can use the same sort of approach with WSS, but it's not as easy to do. You can use the object model to apply an alternate style sheet URL, but I believe you have to touch each different site with your code to do so. You could do it with a PowerShell script or other program, but the idea is the same, you have to loop through the sites, something like this:

SPSite theCollection = new SPSite("http://sitecollectionUrl");  
foreach (SPWeb aWeb in theCollection.AllWebs) {  
   aWeb.AlternateCssUrl = "path to custom style sheet";  
   aWeb.Update();
   aWeb.Dispose();  
}  
theCollection.Dispose();
Abs
Will this just affect the styles though in the richhtmlfield control? When the users are editing the content, they can select from a dropdown to apply heading 1, heading 2 etc, I want to specify what those styles are but just inside the richhtmlfield control, not glabally over the whole site, otherwise, system menus etc start to get affected.
78lro
I see what you're saying, and no my solution isn't specific to that control. I suppose it could be if there's a unique way of identifying those control with CSS, but I reckon you already thought of that. Beyond that, the only thing I can think of is that it might be possible for you to override the default control with one of your own that has a lower sequence ID (although I haven't checked to see if that will work in this case). This post talks about how to do it: http://lawo.wordpress.com/2009/02/04/124/. This one too: http://msdn.microsoft.com/en-us/library/ms463169.aspx.
Abs
A: 

As mentioned above, to change the styles that affect the H1, H2 etc, we just need to specify an alternate stylesheet and in it, specify the styles as the are applied in the richhtmlfield control.

The answer for how to change the table formatting layout is to specify a link to the stylesheet that provides the predefined table formats, Sherman posted a good article that pointed me in the right direction for this.

78lro