Summary

This simple project will help you to build and deploy SharePoint projects based on the Wiki page content type. This feature, existing into SharePoint since version 2007, has dramatically increased its importance in version 2010 as team sites, the basic SharePoint site templates, is now based in this technology. Although team sites have been always thought for intranet collaborative sites, now people are using more and more this type of page for simple publishing sites due to its flexibility and ease of editing.

This usage increase has made clear some limitations, though. One of them is how difficult it is to automate page creation and update. SharePoint has some classes we may use to deploy publishing pages and content types but, when it comes to wiki pages, the only artifact developers have in order to deploy them is exporting an existing site as a template and do some kind of reverse enginery. Unfortunatelly, if we do that we will find plenty of elements to understand and even some encoded information such as webpart definitions. Also, you will find that if you need any particular functionality such as performing some actions on feature deactivation you can be locked by the fact that SharePoint classes are often sealed.

This project was born with two main goals. First, make wiki provisioning as easy as publishing pages provisioning. Finally, to have full control of the activation and deactivation process.

How does it work

The engine is basically a feature receiver that parses a xml file containing all the pages to be deployed with its contents, including layout and webparts. The layout is just the hmtl code that defines the disposition of the elements through the page. SharePoint comes out of the box with some different layouts that can be selected by users from the user interface. Unfortunatelly, this list and its items cannot be changed in any way.

You have, however, the possibility to do it programmatically. This is, for example, the standard html code you are going to use when selecting One column with sidebar from the list above. As you will see in this documentation, you will be able to set different widths (for example 80% - 20%) should you need to. The only limitation is that you won't be able to select this new layout through the user interface.

<table id="layoutsTable" style="width: 100%">
  <tbody>
    <tr style="vertical-align:top">
      <td style="width: 66.6%">
        <div class="ms-rte-layoutszone-outer" style="width:100%">
          <div class="ms-rte-layoutszone-inner" style="min-height:60px;word-wrap:break-word"></div>
        </div>
      </td>
      <td style="width: 33.3%">
        <div class="ms-rte-layoutszone-outer" style="width: 100%">
          <div class="ms-rte-layoutszone-inner" style="min-height:60px;word-wrap:break-word"></div>
        </div>
      </td>
    </tr>
  </tbody>
</table>
<span id="layoutsData" style="display: none">false,false,2</span>

Obviously, you are free to change as many things as you need from the layout above. You could, for instance, add static content to any column in the layout, and you can, of course, add some webparts there. In order to see that, lets first see how you create a page with the unexisting layout. The following listing shows it.

<WikiPages>
  <WikiPage>
    <Title>New Page</Title>
    <Default>false</Default>
      <WikiField>
        <![CDATA[
          <table id="layoutsTable" style="width: 100%">
            <tbody>
              <tr style="vertical-align:top">
                <td style="width: 80%">
                  <div class="ms-rte-layoutszone-outer" style="width:100%">
                    <div class="ms-rte-layoutszone-inner" style="min-height:60px;word-wrap:break-word"></div>
                  </div>
                </td>
                <td style="width: 20%">
                  <div class="ms-rte-layoutszone-outer" style="width: 100%">
                    <div class="ms-rte-layoutszone-inner" style="min-height:60px;word-wrap:break-word"></div>
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
          <span id="layoutsData" style="display: none">false,false,2</span>
        ]]>
      </WikiField>
  </WikiPage>
</WikiPages>

Now, the last thing to do is adding webparts to the new page. This is possibly the more complex piece of this project. However, as a SPWikiProvisioning user, things become really straightforward. The only thing you need to do is adding the webpart declaration to the file and then a pointer to that webpart into the layout, as shown in the following listing.

<WikiPages>
  <WikiPage>
    <Title>New Page</Title>
    <Default>false</Default>
    <WebParts>
      <WebPart>
        <WebPartID>defcefe2-a0c0-4494-9201-53e8be93b5c9</WebPartID>
        <WebPartContent>
          <![CDATA[
          <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
            <Title>Content editor</Title>
            <FrameType>Default</FrameType>
            <Description></Description>
            <IsIncluded>true</IsIncluded>
            <ZoneID>wpz</ZoneID>
            <PartOrder>0</PartOrder>
            <FrameState>Normal</FrameState>
            <Height />
            <Width />
            <AllowRemove>true</AllowRemove>
            <AllowZoneChange>true</AllowZoneChange>
            <AllowMinimize>true</AllowMinimize>
            <AllowConnect>true</AllowConnect>
            <AllowEdit>true</AllowEdit>
            <AllowHide>true</AllowHide>
            <IsVisible>true</IsVisible>
            <DetailLink />
            <HelpLink />
            <HelpMode>Modeless</HelpMode>
            <Dir>Default</Dir>
            <PartImageSmall />
            <MissingAssembly></MissingAssembly>
            <PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
            <IsIncludedFilter />
            <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
            <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
            <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
            <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">SPWikiProvisioning provisioned webpart</Content>
            <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
          </WebPart>
          ]]>
        </WebPartContent>
      </WebPart>
    </WebParts>
    <WikiField>
      <![CDATA[
        <table id="layoutsTable" style="width: 100%">
          <tbody>
            <tr style="vertical-align:top">
              <td style="width: 66.6%">
                <div class="ms-rte-layoutszone-outer" style="width:100%">
                  <div class="ms-rte-layoutszone-inner" style="min-height:60px;word-wrap:break-word"><WebPart id='defcefe2-a0c0-4494-9201-53e8be93b5c9'/></div>
                </div>
              </td>
              <td style="width: 33.3%">
                <div class="ms-rte-layoutszone-outer" style="width: 100%">
                  <div class="ms-rte-layoutszone-inner" style="min-height:60px;word-wrap:break-word"></div>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
        <span id="layoutsData" style="display: none">false,false,2</span>
      ]]>
    </WikiField>
  </WikiPage>
</WikiPages>

Getting started

It you want to get started with SPWikiProvisioning follow this link for list of howtos that will guide you through the process of creating Visual Studio projects from scratch leveraging the features contained in this solution.

 

Last edited Dec 21, 2011 at 9:43 PM by davidmartos, version 6

Comments

No comments yet.