Skip to main content

Elumenotion Blog

Go Search

 
Elumenotion > Elumenotion Blog
Posts and musings about SharePoint, eLumenotion, and random whatnot.
Atlanta Code Camp is this Weekend, Saturday May 19th

For the last few weeks the organizing committee for this year's Atlanta Code Camp (including myself!) has been busily planning and organizing this year's Atlanta Code Camp. This year's event is once again on the campus of Southern Polytechnic State University in Marietta. You can read more and register for the event here: http://www.atlantacodecamp.org/default.aspx.

If you're not familiar with code camps, they are free community‐focused events by and for the .NET developer community. The Atlanta Code Camp draws upon the expertise of local and regional developers, architects, and experts who come together to share their real world experiences, lessons learned, best practices, and general knowledge with other interested individuals.

This event is unique in that it is "for the community, by the community" and is free for all that desire to attend. In past years, the Atlanta Code Camp has provided free training and networking opportunities for 300 of the best, most motivated development professionals. With our larger facility, we're expecting this year to be even bigger and better.

This is a free event and we provide lunch. I hope to see you there!

--Doug

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

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

 

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

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

 

1 - 5 Next
Follow me on twitter!
The Atlanta .NET User Group
MVP Logo
  Archive
  Archive (Calendar)
  Skinner Created Themes
  New Skinner Download
  New Skinner Tutorial

 ‭(Hidden)‬ Admin Links


©  2009 Elumenotion, LLC  |   SharePoint Training, SharePoint Consulting and SharePoint Staffing
8075 Cavendish Place | Suwanee, Georgia 30024 | + 1 (888) 653-5021