Deploying content pages using SharePoint features

Following with the branding topic  in SharePoint 2010 in this post Im going to explain an easy way to deploy content pages using modules and features in sharepoint 2010.

One of the common tasks in SharePoint is the creation of page content, I mean pages based in diferent page layouts, with text, images, media content webparts to show video and soon, in this post Im going to show you how to create a feature that deploy this content pages using the cks dev tools this is a set of templates that could be installed in visual studio 2o1o, cks dev tools came with an important list of templates and tools some of that are templates to create delegate controls, projects templates for create a sharepoint site branding and tools to work with linq-to-sharepoint and tools for deployment, for this post Im going to use a feature of cks dev tools to export the content of a publishing page in a SharePoint Site, we are going to assume that the page exist I mean we are going to assume that the designer finish its work with this page and we are going to proceed to create a feature to install this new page, first of all we need to install the cks dev tools in visual studio, that tools could be download from this url http://visualstudiogallery.msdn.microsoft.com/ee876627-962c-4c35-a4a6-a4d89bfb61dc/

Creating the Project

After download an install the cks dev tools we need to create the project (fig 1), the solution should be created as a farm solution.

fig. 1

Export the content page

As I said in previous lines we are going to assume the contet page exists and lives in the Pages library of in our site, ok to export the page we need to connect our visual studio to the site were the page is located, to do this first click in principal visual studio menu on the option View -> Server Explorer, in the tab that should be open right click on Sharepoint Connections and enter the url of the site where the page is located, after that visual studio add the connection for this site (fig 2).

fig. 2

Now you can see all the structure of the selected site, now the page that we need to package in a feature lives in the pages document library so we should open that library, locate the page we want to package, right click on the page select the option export (fig 3).

fig. 3

After click on the export option an xml file should be appear in our project, this xml file contains all the properties of the publishing page, you can see there the author, editor, etc (fig.4 )

fig. 4

Now we are going to use this metadata to create a module to deploy this page, we need to follow three steps first is download the .aspx content page file from the page library, second we need to create a new module object in our project and third we need to add the downloaded content page file to the module created in second step, our project should looks like fig. 5.

fig. 5

The last step is configure the module with the exported metadata, we need to copy all the tag Module in the xml created by the export option in fig 4, and replace all the tag module in the element.xml module file created in previous step, after that we need to make to changes in the element.xml file in our module first change the property name of the module for publishing which is the correct name of the module, the second step is add the property path of the file tag and set this property with the path of the  .aspx content page in the module (fig 6).

.

fig. 6

After this modifications we can deploy this solution and the content page should be deployed to the page library, we need to have some considerations here one of this considerations is that the page layout attached to the page should exists in the target farm, if your page layout is a custom page layout you need to create a feature to deploy your custom page layout, you can see in my previous post how to do this, in the same way the content type attached to the page layout should exists, in the other hand properties like author could be modified to have coherent values there because it would be possible that the author in source farm does not exists in target farm.

I hope this short post will be helpful.

Advertisements