Using Save Site as Template with Publishing Sites – Conclusion

Wow! You made it this far! I hope you learned some things along the way. You can download the sample project from here: http://www.elumenotion.com/Downloads/MyPublishingFeatures.zip.

Although this may seem like a great deal of work, packaging your page layouts for deployment in proper solutions is a key success factor for large projects. Knowing how to do this work allows a development team and the site’s owners to iterate on a publishing site’s layouts with tools like SharePoint Designer. Knowing how to deal with pages is just as important.

Over the years in our practice we’ve come to realize just how much business owners and content contributors focus a site’s home page and subsite landing pages. Although these quickly become content when content owners claim a publishing site, they are the content creator’s first impression of the site. We find that it is very important to a customer’s overall satisfaction for the base pages to contain content on day one of testing and pilot activities, and this is how we ensure we do a good job.

I am not suggesting that every, or even most, publishing page in a new site should be deployed via your solution package. However, the landing pages are important. If you set them up by hand after each deployment the odds are excellent that they will look different from deployment to deployment and that you will create an impression of poor quality.

Finally, if you are a customer of a consulting company that is building a publishing site, you should insist that they can deploy it via one or more packages and that they are using good version control techniques. If they are depending exclusively on SharePoint Designer and manual configurations you should find a new vendor.

Table of Contents

Using Save Site as Template with Publishing Sites – Introduction

Using Save Site as Template with Publishing Sites – Part 1, Saving the Site and Importing the Solution to Visual Studio

Using Save Site as Template with Publishing Sites – Part 2, Creating the New Custom Visual Studio Solution

Using Save Site as Template with Publishing Sites – Part 3, Fixing Up the Page Layout Module

Using Save Site as Template with Publishing Sites – Part 4, Fixing Up the Publishing Module

Using Save Site as Template with Publishing Sites – Conclusion

Author: Doug Ware

Using Save Site as Template with Publishing Sites – Part 4, Fixing Up the Page Module

Fixing up the page is a bit more complex than the page layout. Some publishing pages are based on page layouts that consist of Web Part Zones while others contain wiki content. The former is less complicated than the latter but I have selected the latter as it is the more common scenario in SharePoint 2010. As with the page layout, the page has some properties that need to be preserved and some properties that need to be preserved but edited by hand. In addition the page also has one very important property that is completely missing in the export that must be added by hand!

Switch to the extract solution in Visual Studio and edit elements.xml for the Pages_ module. I’ve highlighted the pieces you need to apply to the MyPublishingFeatures solution below.

Notice the BinarySerializedWebPart element. The Web Part is actually a plain old Content Editor Web Part. If the Web Part was placed into a normal Web Part zone instead of in wiki content it would appear in an AllUsersWebPart element instead. As it stands because it is a BinarySerializedWebPart we will need to edit this XML in a way that has some downsides I’ll discuss in a bit.

Also notice the PublishingPageContent property. The original page has some formatting which is missing from this field. We have some work to do here as well.

Switch back to the MyPublishingFeatures solution and edit the elements.xml file for the MyPublishingPage feature. Start by editing the Module and File elements so that the Url and Type attributes are correct and so that the File element is not self-closing. The result should look like this:

Next, copy the BinarySerializedWebPart and the highlighted properties shown above and paste them between the opening and closing File elements. What you copy will depend on the actual content fields of your target page, but you do not want system properties like _ModerationStatus, FileLeafRef, or ID. SharePoint will populate these values as is appropriate when it provisions the publishing page on your target site.

You are now ready to fix up the BinarySerializedWebPart if necessary. The problem in my example is that I used a site collection with a different server relative URL to create the prototype compared to the actual target for my destination site. Because of this I need to edit the XML.

This means you must know ahead of time what your publishing site’s URL scheme will be and it detracts from your solution’s flexibility. An alternative is to insert the Web Part programmatically, but this discussion is outside the scope of this series of posts. There is an important disclaimer I need to make here: It is possible to have BinarySerializedWebPart elements in a traditional Web Part zone. For example, this is the case if you have an uncustomized list view. You don’t have to fix up the XML in this case.

Once you’ve dealt with the BinarySerializedWebPart, you need to fix the PublishingPageContent property value. You don’t need the extract solution for this. The content is in the Sample-Page.aspx file contained by the module. Open Sample-Page.aspx in the editor. Locate the PublishingPageContent value and copy it to the clipboard.

Switch back to elements.xml and replace the current value of PublishingPageContent with the contents of the clipboard. The chances are good that your XML is no longer valid. In particular, you will need to edit any instances of &nbsp and change them to &nbsp. Pay close attention to the editor, it will show any invalid XML with a red squiggly line beneath the problem text.

At this point you should remove all of the green text from Sample-Page.aspx. As is the case with the extraneous properties, SharePoint will take care of this when it provisions the module.

Only one step remains; the addition of the very important missing PropertyPublishingPageLayout. This property is what tells SharePoint which page layout to use for the page. Without it you will get a runtime error. Add the following Property within the opening and closing File elements.

<Property
				Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/Sample.aspx, Sample Layout"/>

 

The completed Module XML looks like this:

Deploy the solution and navigate to the page. The result looks like this!

Table of Contents

Using Save Site as Template with Publishing Sites – Introduction

Using Save Site as Template with Publishing Sites – Part 1, Saving the Site and Importing the Solution to Visual Studio

Using Save Site as Template with Publishing Sites – Part 2, Creating the New Custom Visual Studio Solution

Using Save Site as Template with Publishing Sites – Part 3, Fixing Up the Page Layout Module

Using Save Site as Template with Publishing Sites – Part 4, Fixing Up the Publishing Module

Using Save Site as Template with Publishing Sites – Conclusion

 

Author: Doug Ware

Using Save Site as Template with Publishing Sites – Part 3, Fixing Up the Page Layout Module

The previous posts in this series covered the simple steps necessary to get the sample page layout and sample page into a new solution. It was all pretty simple, but at this point you need to be careful and pay attention. I can tell you from personal experience that if you mess up the page layout’s properties, you can break page editing in your site!

Start by switching to the import solution you created in Part 1 (or open it if necessary) and open the elements.xml file for the page layout in the editor. You will be pulling some, but not all, of this information over to the new solution. I have highlighted the pits you will need.

Switch back to the MyPublishingFeatures solution and edit the elements.xml file for the MyPageLayout feature. Start by editing the Module and File elements so that the Url and Type attributes are correct and so that the File element is not self-closing. The result should look like this:

Next, copy the Property elements highlighted above and paste them into the File element to match the following.

You are almost done with the page layout, but there is one critical step remaining! The Value attribute of the PublishingAssociatedContentType Property is formatted incorrectly. You must edit the value to match the following format:

;#ContentTypeName;#ContentTypeID;#

In this case the Value becomes

 ;#Article Page;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D;#

Save your work. The page layout is done and you are now ready to take care of the publishing page which, unfortunately, is slightly more complicated.

Table of Contents

Using Save Site as Template with Publishing Sites – Introduction

Using Save Site as Template with Publishing Sites – Part 1, Saving the Site and Importing the Solution to Visual Studio

Using Save Site as Template with Publishing Sites – Part 2, Creating the New Custom Visual Studio Solution

Using Save Site as Template with Publishing Sites – Part 3, Fixing Up the Page Layout Module

Using Save Site as Template with Publishing Sites – Part 4, Fixing Up the Publishing Module

Using Save Site as Template with Publishing Sites – Conclusion

Author: Doug Ware

Using Save Site as Template with Publishing Sites – Part 2, Creating the New Custom Visual Studio Solution

At this point I have saved my publishing site as a template and imported two modules into a new Visual Studio solution. The solution to which I have imported is an intermediate step and, as is the case with the solution I exported, it won’t work if I try to use it. There are several things I’ll need to fix up for it to work. Usually when I do this, I have an existing project that has the rest of the features for my custom publishing site. However to make this tutorial easy to follow I will start from scratch.

Begin by creating a new empty SharePoint project in Visual Studio 2010. I named mine MyPublishingFeatures. You can select either Farm or Sandbox as these features are available in either case, but I chose Farm.

After the new solution opens, add a new item by pressing CTRL+SHIFT+A, select the Module project item template and name it MyPageLayout. Repeat the process and make another module named MyPublishingPage. Then delete both of the Sample.txt files. At this point, the solution should look like this:

In Solution Explorer, right-click MyPageLayout and select Add|Existing Item…

Browse to the import project you created in the previous post and select Sample.aspx. This is the sample page layout. Repeat this process for MyPublishingPage and add the Sample-Page.aspx file to module. Solution Explorer now matches the following.


Now that we have the new project set up, it’s time to make all of the changes necessary for the whole thing to work, starting with the page layout.

Table of Contents

Using Save Site as Template with Publishing Sites – Introduction

Using Save Site as Template with Publishing Sites – Part 1, Saving the Site and Importing the Solution to Visual Studio

Using Save Site as Template with Publishing Sites – Part 2, Creating the New Custom Visual Studio Solution

Using Save Site as Template with Publishing Sites – Part 3, Fixing Up the Page Layout Module

Using Save Site as Template with Publishing Sites – Part 4, Fixing Up the Publishing Module

Using Save Site as Template with Publishing Sites – Conclusion

 

Author: Doug Ware

Using Save Site as Template with Publishing Sites – Part 1, Saving the Site and Importing the Solution to Visual Studio

The Save site as a template link is not available on the Site Settings page of a publishing site. However, you can still access the page by appending /_layouts/savetmpl.asx to your site’s base URL.

I usually complete the page as follows, but keep in mind that it doesn’t matter what you name the solution because the resulting file is just an intermediate step that gets thrown away.

Make sure you check Include Content to include the publishing pages!

Save the solution to your local machine and go through the initial steps to import the solution package into a new solution that I covered in Save Site As Template + Import SharePoint Solution Package == Love.

You need to import the modules for the page layout and the publishing page. The page layouts can be hard to find. They are usually, but not always, in a module named _catalogsmasterpage_FeaturesPublishingReources. You can ensure you select the right one by hovering over the Name; the tooltip lists the item’s contents.

The page is easier to find, it should be in a Module named Pages_. Once you have selected the two Modules, click Finish to complete the import.

The new solution should look something like the following. Leave it open because you will need it in the remaining steps.

Table of Contents

Using Save Site as Template with Publishing Sites – Introduction

Using Save Site as Template with Publishing Sites – Part 1, Saving the Site and Importing the Solution to Visual Studio

Using Save Site as Template with Publishing Sites – Part 2, Creating the New Custom Visual Studio Solution

Using Save Site as Template with Publishing Sites – Part 3, Fixing Up the Page Layout Module

Using Save Site as Template with Publishing Sites – Part 4, Fixing Up the Publishing Module

Using Save Site as Template with Publishing Sites – Conclusion

 

Author: Doug Ware

Using Save Site as Template with Publishing Sites – Introduction

This is the first part of a multipart series of posts that will teach you how to leverage the Save Site as Template and Import SharePoint Solution Package features to facilitate development and creation of page layouts and publishing pages via Visual Studio and SharePoint solution packages. If you arrived at this post because you’d like to be able to save a publishing site as a template and deploy the resulting template, I am sorry to say that that is simply not possible.

Before you get started with this series you should read two posts I wrote a couple of years ago to get a handle on the basic techniques.

Save Site As Template + Import SharePoint Solution Package == Love

How to Copy Feature Elements in Visual Studio SharePoint Solutions

If you found this post, you probably already know that the Save site as template link does not display on the Site Settings page of a publishing site. There is a good reason for this; SharePoint cannot produce a working template from a publishing site! However, it is possible to access the functionality by navigating directly to a page, and a developer can use the contents of the resulting package in their own packages provided she knows what to fix and how to fix it.

In this series of articles I’ll teach you how it is done using a sample page layout and a sample publishing page. The result will be a deployable solution that properly provisions the page layout and the page based on the layout.

I created my sample page layout using SharePoint Designer 2010. It is a copy of the ArticleLeft.aspx page layout and, just like the original, it uses the out of the box Article Page content type. I gave it the very imaginative name of Sample.aspx.

My publishing page has an equally creative title, Sample-Page.aspx, and it contains some formatted text and a Content Editor Web Part within the Page Content field. It looks like this:

Table of Contents

Using Save Site as Template with Publishing Sites – Introduction

Using Save Site as Template with Publishing Sites – Part 1, Saving the Site and Importing the Solution to Visual Studio

Using Save Site as Template with Publishing Sites – Part 2, Creating the New Custom Visual Studio Solution

Using Save Site as Template with Publishing Sites – Part 3, Fixing Up the Page Layout Module

Using Save Site as Template with Publishing Sites – Part 4, Fixing Up the Publishing Module

Using Save Site as Template with Publishing Sites – Conclusion

 

Author: Doug Ware