A few weeks ago one of my colleagues and I had to deal with a strange behavior in MOSS 2007: After creating a WCMS / Publishing page (not Site) there were multiple WebParts of the same type on the page. It was not possible to find a pattern of this behavior because there were sometimes 2 or sometimes even more than 5 WebParts of the same type on the page.
So I have invested some hours to find the problem… In order to understand the problem we need a short introduction to SharePoint 2007 templates.
(This is just an example how it looked like… we didn’t use the document library and we didn’t modify the out of the box files)
ProvisionedFiles.xml and one.xml
A Site Definition contains multiple templates for creating a web site in SharePoint 2007. The STS Site Definition contains templates for creating a team site, a blank site and a document workspace. You can find the onet.xml here: \12\TEMPLATE\SiteTemplates\sts\xml\onet.xml.
When it comes to WCMS / Publishing you have also Site Definitions. The difference between Collaboration and Publishing is that Publishing uses both Master pages and Page Layouts. In order to upload your own Master pages and Page Layouts to SharePoint a feature called PublishingLayouts is loaded during the creation of a site collection which uploads your Master pages and Page Layouts to the "_catalogs/masterpages/" folder.
The file responsible for the upload is the ProvisionedFiles.xml. Furthermore if you want to create pages you need to “register” the pages as a definition in this file.
You can also define Web Parts which should be created when you create a page. You simply insert the Web Part .xml definition like you would do it in the onet.xml.
Now you can create your page and a Web Part is automatically placed at the site.
Strange behavior with multiple WebParts
But why is there sometimes more than 1 WebPart created although I have only inserted 1 .xml definition to the ProvisionedFiles.xml? Well here is the answer:
- If you create a web site the onet.xml is used. So it will never happen that there is more than 1 WebPart because you can see the WebPart .xml definition in the onet.xml.
- If you create a page the Page Layout is used which is stored at the "_catalogs/masterpages/" folder instead of the ProvisionedFiles.xml.
And yeah after inspecting the Page Layout with SharePoint Designer 2007 I discovered that there a multiple instances of my WebPart in the Page Layout:
And this is the reason why there is more than 1 WebPart of the same type stored in the Page Layout:
- When you create a Site Collection and the feature PublishingLayouts is activated, it copies the Master pages and Page Layouts to the "_catalogs/masterpages/" folder.
- In the same process all WebParts specified in the ProvisionedFiles.xml are stored in the Page Layout itself! If you deactivate the feature and activate it again the WebPart is stored again and again because there is no check if the WebPart is already stored in the Page Layout. You can find out by yourself and create an exception (don’t forget to iisreset before you activate the PublishingLayouts feature):
- So if you want to create a page after you created the above exception the page creation will fail with the following exception:
So here is what I have learned:
- All WebParts specified in ProvisionedFiles.xml are copied to the corresponding Page Layout in the "_catalogs/masterpages/" folder when you activate the PublishingLayouts feature.
- If you activate the PublishingLayouts feature multiple times the copy process stores again and again the same WebPart in the Page Layout.
- If you create a page all WebParts from the Page Layout are copied to the new page.
So what is the solution? Removing the redundant WebParts didn’t work because I couldn’t save the modified Page Layout… So I’m still looking for a solution.
Do you want to learn SharePoint, enhance your skills or do you need professional material and tools?