Saturday, April 23, 2005

Modifying site definitions - changes in Onet.xml , adding AllUsersWebPart element

All sites and areas in SharePoint Portal Server and Windows SharePoint Services are based on custom site definitions - these are all the files you can find in the 60 hive -
C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\ directory (1033 is the locale ID for English - so if you have a Portal in another language you will another number). In this directory you will find a number of directory which contain all the templates for different site and area types. For a nice overview check out Heathers blog - SharePoint site definitions - Mapping files to pages on a SharePoint sites

One of the interesting files you will find in these directories is onet.xml - this file contains the bigger part of how your site/area will look like - common customizations for this file are
  • Specify an alternate cascading style sheet (CSS) file, JavaScript file, or ASPX header file for a site definition.

  • Modify navigation areas for the home page and list pages.

  • Add a list definition as an option to the Create page.

  • Add a document template for creating document libraries.

  • Define a configuration for a site definition, specifying the lists, modules, files, and Web Parts that are included when a site is instantiated.


  • The last option was something I wanted to try - including webparts when a site is instantiated. Basically I wanted all of the "My sites" to contain an extra webpart on the private side.
    Steps I took:
  • Write a custom webpart (and even test it, if you feel like it...)

  • Add a strong name to the webpart assembly and deploy it to the GAC

  • Deploy the webpart on the server with stsadm.exe


  • The last step is modifying onet.xml for My Site (located in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\SPSMSITE\XML directory) - in this XML file you will find a Modules element and inside the Modules element the AllUsersWebPart element. So if you want that a webpart is added to a site/area by default you can add an extra AllUsersWebPart element
    for your custom webpart. See example

    <AllUsersWebPart WebPartZoneID="MiddleRightZone" WebPartOrder="4"><![CDATA[<WebPart
    xmlns="http://schemas.microsoft.com/WebPart/v2"><Assembly>RecentDocsWebPart,
    Version=1.0.0.1, Culture=neutral, PublicKeyToken=7f713d9ae1e786b0</Assembly><TypeName>RecentDocsWebPart.RecentDocsWebPart</TypeName><Title>Recent
    Documents Enhanced</Title><Description>Demo</Description><PartOrder>4</PartOrder><FrameType>TitleBarOnly</FrameType><AllowRemove>true</AllowRemove><AllowMinimize>true</AllowMinimize><IsVisible>true</IsVisible></WebPart>]]></AllUsersWebPart>


    This may look fairly complex, but is actually fairly easy:
  • Copy <AllUsersWebPart WebPartZoneID="MiddleRightZone" WebPartOrder="4"><![CDATA[ and ;]]></AllUsersWebPart>

  • Add the custom webpart you want to add to the site definition to a webpartpage the normal way, and then click Export

  • The previous step will generate a DWP file - this actually a XML file, just take the contents of the file and paste it between the CDATA brackets


  • Unfortunately, this didn't work for the "My Site" so I tried it for the "Community Area" template and it didn't work for existing areas but only for newly created areas. Unfortunately this doesn't even work for the "My Site", even when users access your portal for whom the "My Site" still needs to be generated. I guess it will be the easiest to just open the "My Site" in FrontPage 2003 and add the webpart this way or create code which will add the webpart from code... I guess some people will call this YASQ, Yet Another SharePoint Quirk,....

    2 comments:

    1. Anonymous11:32 AM

      I just opened my "My Site" and switched into "Shared View" in IE. Then you can add Web Parts which will show up for all people. No FrontPage required at all...

      ReplyDelete
    2. Unfortunately, I wanted to add a webpart to the private side.

      ReplyDelete