Today we're going to continue our walk through a practical integration and deployment exercise. This began as a project to add centralized global navigation schemes to a custom SharePoint master page. We're going to extend that today to use publishing features to share the master page itself across multiple site collections. Each of these is covered in a separate post:
· [Part I] In the first post, we introduced master page customization to add centralized navigation support to the master page
· [Part II] Centralized publishing of common master pages, using Heather Solomon’s techniques outlined at http://heathersolomon.com/blog/articles/servermstpageforsitecollect_feature.aspx
· [Part III] Packaging of the feature as a WSP file, using the WSPBuilder application from Codeplex (http://www.codeplex.com/wspbuilder)
· [Part IV] Automated installation of the solution package, using the SharePoint Installer from Codeplex (again!) at http://www.codeplex.com/sharepointinstaller
Defining Common Master Pages
This technique in this section is adapted from, and indebted to, Heather Solomon’s excellent article on the topic at http://heathersolomon.com/blog/articles/servermstpageforsitecollect_feature.aspx
1. In your server’s “12 Hive” (usually c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12) go to the Features directory inside the TEMPLATE folder. Copy the PublishingLayouts folder to a new folder in the root of Features. The folder name will become the name for your new feature. Here, we’re using CustomMasterPages.
2. Open the new folder, and clean out all subfolders, leaving only Feature.xml and ProvisionedFiles.xml. To create a clean file set, at a minimum clear out the contents of each sub folder in the directory (en-us
3. Copy/paste content from original master pages to new pages outside the database [Notepad]. See above for typical edits.
4. Edit the ProvisionedFiles.xml file in Notepad. We are going to delete most of the content and keep only the OSGMasterPages Module tag and the PublishingLayoutsPreviewImages Module tag. [See text below.] We use one node for each master page file (this solution has three master pages.)
<!-- _lcid="1033" _version="12.0.6301" _dal="1" -->
<!-- _LocalBinding -->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="OSGMasterPages" Url="_catalogs/masterpage" Path="MasterPages" RootWebOnly="TRUE">
<File Url="001.master" Type="GhostableInLibrary">
<Property Name="ContentType" Value="Title 001" />
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/0016.gif, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/0016.gif" />
<Property Name="MasterPageDescription" Value="Description 001" />
</File>
<File Url="002.master" Type="GhostableInLibrary">
<Property Name="ContentType" Value="Title 002" />
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/0016.gif, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/0016.gif" />
<Property Name="MasterPageDescription" Value="Description 002" />
</File>
<File Url="003.master" Type="GhostableInLibrary">
<Property Name="ContentType" Value="Title 003" />
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/0016.gif, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/0016.gif" />
<Property Name="MasterPageDescription" Value="Description 003" />
</File>
</Module>
<Module Name="PublishingLayoutsPreviewImages" Url="_catalogs/masterpage" IncludeFolders="??-??*" Path="" RootWebOnly="TRUE">
<File Url="0016.gif" Name="Preview Images/0016.gif" Type="GhostableInLibrary">
</File>
</Module>
</Elements>
9.Create a preview image in the language folder (in this case, en-us). Local Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\CustomMasterPages\en-us. As you can see above, we are using a file named 0016.gif.
Next, open Feature.xml file in Notepad.
· Change the Feature ID to a unique GUID. You can generate GUIDs in Visual Studio, (Tools - Create GUID - Registry Format - Copy). If you don’t have Visual Studio, get it! In the meantime, you can also use a neat online site to get a new one at http://www.guidgen.com. Paste the new GUID into the Feature ID node (don’t keep any brackets).
<Feature Id="FDFCD4C4-F0D9-43b5-8739-A33681049657"
· Update the title: Title="Custom Master Pages"
· Update the description: Description="Custom master pages for use across multiple site collections."
· Change the Hidden state to False: Hidden="False"
Save the Feature.xml file. You should wind up with something like this.
<!-- _lcid="1033" _version="12.0.4518" _dal="1" -->
<!-- _LocalBinding -->
<Feature Id="1e5ad034-4b11-4dcc-9e73-0208740d45a5"
Title="Custom Master Pages"
Description="Custom master pages from XXXXX to use in multiple site collections"
Version="12.0.0.1"
Scope="Site"
Hidden="FALSE"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="ProvisionedFiles.xml"/>
</ElementManifests>
</Feature>
At this point, we could use stsadm -o installfeature -name YourFeatureDirectoryName to install the feature, and then activate and test it. But we’re going to go further and package the solution for automated installation.
Page Not Found Error
If you get any odd “file not found” or “page not found” errors, you may have used SharePoint Designer (SPD) to modify the master pages. SPD may change the code automatically to remove the tilde and leading slash from some of the console registrations in your master page.
Original:
<%@ Register TagPrefix="wssuc" TagName="DesignModeConsole" src="~/_controltemplates/DesignModeConsole.ascx" %>
SPD Alterations:
<%@ Register TagPrefix="wssuc" TagName="DesignModeConsole" src="_controltemplates/DesignModeConsole.ascx" %>
To avoid this, don’t open master pages for final editing using Sharepoint Designer. Use Notepad or similar tools to work on the file outside the content database.
It's great working on the SharePoint cloud to get a lot of the development done. There's a free trial here: http://www.itstrategists.com/Trial.aspx
Posted by: Connor | 09/17/2009 at 09:00 PM