Showing posts with label SharePoint 2010 Enterprise Wiki. Show all posts
Showing posts with label SharePoint 2010 Enterprise Wiki. Show all posts

21/11/2012

Adding your custom styles in your SharePoint 2010 Rich Html Editor

This blog post describes how to add a custom styles in your Rich Html Editors.

The new style will appear when editing e.g. a wiki or site page in the Markup-Style dropdown:

 
 
Or in the Table-Style drop down:
 


1: Create the style
Add CSS file to managed folder /layouts/Namespace/wiki.css

Example headings (Markup-Style dropdown):

H1.ms-rteElement-MyH1
{
    /* This name will be displayed in the drop down */
    -ms-name: "My heading 1";
}
.ms-rteElement-MyH1
{
    background-color: #597087;
    color: #ffffff;
}

Example tables (Table-Style drop down) - Table with coloured header row and zebra stripes:

.ms-rteTable-10,
.ms-rteTableHeaderFirstCol-10,
.ms-rteTableHeaderLastCol-10,
.ms-rteTableHeaderOddCol-10,
.ms-rteTableHeaderEvenCol-10,
.ms-rteTableFirstCol-10,
.ms-rteTableLastCol-10,
.ms-rteTableOddCol-10,
.ms-rteTableEvenCol-10,
.ms-rteTableFooterFirstCol-10,
.ms-rteTableFooterLastCol-10,
.ms-rteTableFooterOddCol-10,
.ms-rteTableFooterEvenCol-10,
TD.ms-rteTable-10,
TH.ms-rteTable-10,
.ms-rtetablecells
{
    /* This name is displayed in the drop down */
    -ms-name:"Table Style 4 - Zebra stripes";
    border-left: none;
    border-right: none;
    text-align:left;
    line-height:2;
    vertical-align: top;
    padding:2px;
    padding-left: 5px;
}
.ms-rteTableHeaderFirstCol-10,
.ms-rteTableHeaderLastCol-10,
.ms-rteTableHeaderOddCol-10,
.ms-rteTableHeaderEvenCol-10
{
    background-color: #b5c1ce;
    color: white;
    border-top: solid #D5DCE3 1px; 
    border-bottom: solid #D5DCE3 1px;
}
.ms-rteTableFooterFirstCol-10,
.ms-rteTableFooterLastCol-10,
.ms-rteTableFooterOddCol-10,
.ms-rteTableFooterEvenCol-10
{
    font-weight: bold;
    border-top: solid #D5DCE3 2px; 
    border-bottom: solid #D5DCE3 2px;
}
.ms-rteTableFirstCol-10, 
.ms-rteTableLastCol-10
{
    font-weight: bold;
}
.ms-rteTable-10 tr.ms-rteTableOddRow-10 {
 background-color: #eee;
}
.ms-rteTable-10 tr.ms-rteTableEvenRow-10 {
 background-color: #fff;
}

2: Add Css to master page or default page layout

<SharePoint:CssRegistration ID="CssRegistrationWiki" 
   name="/_layouts/Namespace/wiki.css"  After="corev4.css" runat="server"/>3: 


It is not possible to remove any existing table or heading styles. You can change existing style or add new styles, but not delete. Also, it is not possible to change the name of an existing style.

A common thing you would like to do is change the default table style, this can be done by using "-default" instead of "-10" in the style selectors in the example above. But remember that the name of the default table style will never be changed.

There is a way to do this but it requires you to add a parameter every place the "PublishingWebControls:RichHtmlField" field is used, see this blog post at sharepoint blues.

07/11/2012

Create custom enterprise wiki

How to create a custom enterprise wiki


1: Create a web template that extends the enterprise wiki template:

<?xml version="1.0" encoding="utf-8"?>
<Templates xmlns:ows="Microsoft SharePoint">
    <Template Name="YourWiki" ID="0">
        <Configuration ID="0"
                       Title="Your Enterprise Wiki"
                       Hidden="FALSE"
                       ImageUrl="/_layouts/images/stts.png"
                       Description="..."
                       DisplayCategory="Custom"
                       ProvisionClass="<Namespace>.YourProvider"
                       ProvisionAssembly="<namespace>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxx" 
                       RootWebOnly="False">
        </Configuration>
    </Template>
</Templates>

2: Deploy the custom template to the folder: {SharePointRoot}\Template\1033\XML

3: Create the Custom Provider class:

class YourProvider : SPWebProvisioningProvider
{
    public override void Provision(SPWebProvisioningProperties props)
    {
        props.Web.ApplyWebTemplate("ENTERWIKI#0")
        var code = new SPSecurity.CodeToRunElevated(CreateSite);
        SPSecurity.RunWithElevatedPrivileges(code); //Excecute elevated
    }
    private void CreateSite() 
    {
        using (SPSite site = new SPSite(Properties.Web.Site.ID))
        {
            using (SPWeb web = site.OpenWeb(Properties.Web.ID))
            {
                // your custom code
            }
        }
    }     
}

That's it :)