<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>SharePoint Magazine &#187; feature</title>
	<atom:link href="http://sharepointmagazine.net/tag/feature/feed" rel="self" type="application/rss+xml" />
	<link>http://sharepointmagazine.net</link>
	<description>SharePoint Magazine is an online Magazine dedicated to the world of SharePoint</description>
	<lastBuildDate>Mon, 05 Jul 2010 09:14:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Deploying the Master Page (Master Pages and SharePoint part 4 of 6)</title>
		<link>http://sharepointmagazine.net/technical/development/deploying-the-master-page</link>
		<comments>http://sharepointmagazine.net/technical/development/deploying-the-master-page#comments</comments>
		<pubDate>Fri, 24 Oct 2008 07:20:53 +0000</pubDate>
		<dc:creator>ggalipeau</dc:creator>
				<category><![CDATA[Customisation]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[cab]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[designer]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[master]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[solution]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[wsp]]></category>

		<guid isPermaLink="false">http://sharepointmagazine.net/?p=1273</guid>
		<description><![CDATA[This is the fourth article in a six-part series on ASP.NET Master Pages and SharePoint. In the previous article of this series we discussed how to build a customized master page in SharePoint Designer. At the end of the previous article we discussed that making the modifications directly in SharePoint Designer is not the most deployable solution for production life cycle environments.
This article will discuss using features to deploy a custom master page to the master page gallery.

]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>This is the fourth article in a six-part series on ASP.NET Master Pages and SharePoint.</p>
<ol>
<li><a href="http://sharepointmagazine.net/technical/development/introduction-to-master-pages">Introduction to Master Pages.</a></li>
<li><a href="http://sharepointmagazine.net/technical/development/examining-the-out-of-the-box-master-pages-in-sharepoint">Examining the out of the box Master Pages in SharePoint.</a></li>
<li><a href="http://sharepointmagazine.net/technical/customisation/developing-a-custom-master-page-master-pages-and-sharepoint-part-3-of-6">Developing a custom Master Page for SharePoint.</a></li>
<li><strong>Deploy a Master Page for a production ready system.</strong></li>
<li>Customizing the Application.master Page.</li>
<li>Incorporating a Master Page into a SharePoint site definition<strong></strong></li>
</ol>
<p>In the previous article of this series we discussed how to build a customized master page in SharePoint Designer. At the end of the previous article we discussed that making the modifications directly in SharePoint Designer is not the most deployable solution for production life cycle environments.</p>
<p>This article will discuss the other option to customize and deploy a master page for a production ready system.</p>
<h2>Features</h2>
<p>Features are SharePoint&#8217;s way to activate and deactivate certain code on particular site and/or site collection, within a SharePoint website. Features can contain things like &#8211; what webparts should be available, what lists should be available, what actions should be on list menus, etc&#8230;</p>
<p>Features can also deploy master pages to the master page gallery of a SharePoint site and/or site collection. Using a feature to deploy the master pages gives us reusable files that can be deployed to any SharePoint environment through SharePoint commands. This means that we can create build scripts to deploy our master page to a master page gallery. This is much better than the copy and paste method of SharePoint Designer we showed in the previous article.</p>
<p>Features contain two main files:</p>
<ol>
<li>Feature.xml -When a feature is installed SharePoint looks for the feature.xml file to determine how to deploy the feature. The feature.xml file defines the feature and provides the paths to the other files involved in deploying the feature.</li>
<li>Elements Manifest &#8211; this file is referred to from the feature.xml. This is the file that determines what the feature should do when it is activated.</li>
</ol>
<p>Features can be installed to a SharePoint environment through stsadm commands. Stsadm is the command line tool for SharePoint and is used for multiple administrative and development operations in SharePoint.</p>
<p>Once a feature is installed on a SharePoint machine, it can be activate or deactivated on a particular SharePoint site or site collection. Every feature.xml file contains a &#8220;Scope&#8221; attribute. If the scope of a feature is &#8220;Web&#8221;, that means that the feature can only be activated at the SharePoint site level. If the scope of a feature is &#8220;Site&#8221;, that means the feature can only be activated at the SharePoint site collection level. Site Collections contain all the sites in a SharePoint tree, thus if a feature is activated at a site collection, it is activated for all the sites in the site collection. If a feature is activated at a site, it is activated for that site only.</p>
<p>To activate a feature you can go to a site and/or site collection and then go to the Site Settings. In the site settings you will see a link for &#8220;Site features&#8221;. If you are on a top level site in the site collection, you will also see a link for &#8220;Site collection features&#8221;.</p>
<p>When you click on the &#8220;Site features&#8221; and/or &#8220;Site collection features&#8221; link you will go to the feature activation page for the site and/or site collection respectively. From this page you can activate or deactivate sites for the site and/or site collection.</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2008/10/sitesettingsfeatures.jpg"><img class="alignnone size-medium wp-image-1275" src="http://sharepointmagazine.net/wp-content/uploads/2008/10/sitesettingsfeatures-300x55.jpg" alt="" width="300" height="55" /></a></p>
<h2>Custom Master Page file</h2>
<p>To customize a SharePoint master page with a feature, you need to create a custom master page file. This file gets uploaded to the master page gallery in SharePoint through the feature.</p>
<p>There are multiple ways to create your own master page files. Here are a few techniques I recommend:</p>
<ol>
<li>Copy Technique:
<ul style="lower-alpha">
<li>Copy the default.master from %Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\Global.</li>
<li>Make your changes directly to the html (in the copied file).</li>
<li>Make sure the copy file has a different name than default.master.</li>
</ul>
</li>
<li>Designer Technique
<ul style="lower-alpha">
<li>Make your changes in SharePoint designer as described in the previous article: http://sharepointmagazine.net/technical/customisation/developing-a-custom-master-page-master-pages-and-sharepoint-part-3-of-6.</li>
<li>Do not save these changes against your site &#8211; you can do this against a test site to make things easier.</li>
<li>Copy the html out into a custom master file and give it a unique name.</li>
</ul>
</li>
<li>Minimal Master technique
<ul style="lower-alpha">
<li>Make a master page file with the minimal master html code found here: <a href="http://msdn.microsoft.com/en-us/library/aa660698.aspx">http://msdn.microsoft.com/en-us/library/aa660698.aspx</a></li>
<li>The minimal master html is a master page with all the content place holders that you will need for SharePoint. This is a good starting point if you want to start from scratch in creating your master page. You should become familiar with what all the content place holders are for when using this technique.</li>
<li>Save this file as a new master file and give it a unique name.</li>
</ul>
</li>
</ol>
<h2>Create the Feature</h2>
<p>Features are created in Visual Studio and then moved into the SharePoint 12 hive %Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES. After the feature is in the 12 hive, stsadm commands can be used to deploy the feature to the SharePoint environment. Then the feature needs to be activated on the SharePoint site.</p>
<p><span style="underline;">Steps to create a feature for Master Page deployment:</span></p>
<p><strong><em>Note</em></strong><em>: We will not be using any tools like Visual Studio Extensions for WSS or WSPBuilder for this walkthrough. However, I recommend using these tools to wrap the features in solutions. We will talk more about this in the last article in this series.</em></p>
<p><em></em></p>
<ol>
<li>Open Visual Studio</li>
<li>Create a New Project</li>
<li>Choose a Class Library project (for this walkthrough I am referring to a C# class library, but the steps are the same for other types)</li>
<li>Call it DemoMasterPageFeature</li>
<li>Delete Class1.cs</li>
<li>Add a new folder to the project and call the folder &#8220;12&#8243;</li>
<li>Add a new folder to the &#8220;12&#8243; folder, call it &#8220;Template&#8221;</li>
<li>Add a new folder to the &#8220;Template&#8221; folder, call it &#8220;Features&#8221;</li>
<li>Add a new folder to the &#8220;Features&#8221; folder, call it &#8220;DemoMasterPage&#8221;</li>
<li>Add a new folder to the &#8220;DemoMasterPage&#8221; folder, call it &#8220;MasterPages&#8221;</li>
<li>Add a new master page file to the MasterPages folder
<ul>
<li>There are multiple ways to create this file
<ul>
<li>You can copy the one from SharePoint</li>
<li>You can copy a modified one out of SharePoint Designer. If you have been following this series you can go to article 3 {insert link here} and use the html we modified in SharePoint Designer for your new master page file.</li>
<li>You can start with a minimal master page <a href="http://msdn.microsoft.com/en-us/library/aa660698.aspx">http://msdn.microsoft.com/en-us/library/aa660698.aspx</a></li>
</ul>
</li>
<li>We are going to use the technique of copying the one from SharePoint
<ul>
<li>Go to %Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\Global.</li>
<li>Copy the default.master</li>
<li>Paste it in the MasterPages folder (in the Visual Studio project)</li>
</ul>
</li>
<li>Rename the file demomasterpage.master</li>
</ul>
</li>
<li>Add a feature.xml file to the DemoMasterPage folder.
<ul>
<li>This file tells SharePoint how to install the master page</li>
<li>It must be called &#8220;feature.xml&#8221;</li>
<li>Put the following xml in it</li>
</ul>
<p>&lt;Feature Id=&#8221;95F25D4A-D256-4158-96FE-010F599149CC&#8221; Title=&#8221;Demo Master Page&#8221;<br />
Scope=&#8221;Site&#8221; Version=&#8221;1.0.0.0&#8243; Hidden=&#8221;FALSE&#8221; DefaultResourceFile=&#8221;core&#8221; xmlns=http://schemas.microsoft.com/sharepoint/ Description=&#8221;This Feature contains the demo master page&#8221;&gt;<br />
&lt;ElementManifests&gt;<br />
&lt;ElementManifest Location=&#8221;elements.xml&#8221; /&gt;<br />
&lt;ElementFile Location=&#8221;MasterPages\demomasterpage.master&#8221; /&gt;<br />
&lt;/ElementManifests&gt;<br />
&lt;/Feature&gt;</p>
<ul>
<li>Notice the following:
<ul>
<li>Scope &#8211; this tells SharePoint where to install the feature. Our scope is &#8220;site&#8221;, thus we want to install the feature at the site collection level. This is because our master page gallery lives at the site collection level. If we wanted to install the feature at the sub-web level, it would say &#8220;web&#8221;</li>
<li>ElementManifest &#8211; this tells SharePoint the other files involved in creating this feature. Remember, SharePoint only knows to look at the feature.xml file when installing a feature, so the feature.xml file must tell SharePoint about the other files involved.</li>
<li>Id &#8211; this is the unique GUID for the feature. It must be unique. So, if you create multiple features, make sure you use a unique GUID here. This is also how we can reference the feature when we start building solutions.</li>
</ul>
</li>
</ul>
</li>
<li>Add an elements.xml file to the DemoMasterPage folder
<ul>
<li>This file tells SharePoint what to do with this feature. For example: we want to deploy our master page to the master page gallery. This is the file that will tell SharePoint to do that.</li>
<li>It doesn&#8217;t have to be called elements.xml. But, it does have to be called whatever you put as the ElementManifest Location in the feature.xml file. I like to use elements.xml when I create these files</li>
<li>Put the following xml in it</li>
</ul>
<p>&lt;Elements xmlns=&#8221;http://schemas.microsoft.com/sharepoint/&#8221;&gt;<br />
&lt;Module Name=&#8221;DemoMasterPage&#8221; Url=&#8221;_catalogs/masterpage&#8221; Path=&#8221;MasterPages&#8221; RootWebOnly=&#8221;FALSE&#8221;&gt;<br />
&lt;File Url=&#8221;demomasterpage.master&#8221; Type=&#8221;GhostableInLibrary&#8221; /&gt;<br />
&lt;/Module&gt;<br />
&lt;/Elements&gt;</p>
<ul>
<li>Notice the following:
<ul>
<li>Url &#8211; this is how we tell SharePoint to put the file in the master page gallery. _catalogs/masterpage is the location of the master page gallery when dealing with site collections. We know we are dealing with site collections because the feature.xml file has a scope of &#8220;site&#8221;.</li>
<li>File &#8211; this tells SharePoint the name of the file it is going to put at the master page gallery. The type is &#8220;GhostableInLibrary&#8221; &#8211; this means the file is still going to be on the 12 hive and SharePoint is going to keep a Ghosted reference to the file. Please refer to article 3 <a href="http://sharepointmagazine.net/technical/customisation/developing-a-custom-master-page-master-pages-and-sharepoint-part-3-of-6">http://sharepointmagazine.net/technical/customisation/developing-a-custom-master-page-master-pages-and-sharepoint-part-3-of-6</a> for more information about Ghosting.</li>
</ul>
</li>
</ul>
</li>
<li>Build the project in order to save your changes.</li>
</ol>
<p>The final folder/file structure should look like this:</p>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2008/10/demomasterpagestructure.jpg"><img class="alignnone size-medium wp-image-1282" src="http://sharepointmagazine.net/wp-content/uploads/2008/10/demomasterpagestructure-300x196.jpg" alt="" width="300" height="196" /></a></p>
<h2>Deploying the Feature</h2>
<p>There are 2 steps to deploy a feature:</p>
<ol>
<li>Copy the contents to the 12 hive.
<ul>
<li>Copy the folder &#8220;DemoMasterPage&#8221; (this is the folder we created in the Visual Studio solution in the last section). Be careful to only copy the &#8220;DemoMasterPage&#8221; folder, not all the folders we created.</li>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2008/10/demomasterpagestructurehighlighted.jpg"><img class="alignnone size-medium wp-image-1285" src="http://sharepointmagazine.net/wp-content/uploads/2008/10/demomasterpagestructurehighlighted-300x193.jpg" alt="" width="300" height="193" /></a><br />
Also, you probably won&#8217;t be able to copy from Visual Studio. So, go to windows explorer to do the copy of the folder.</p>
<li>Paste the &#8220;DemoMasterPage&#8221; folder in %Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES.</li>
</ul>
</li>
<li>Run stsadm commands to install the feature
<ul>
<li>Open up a command prompt</li>
<li>Enter the following: cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN.<br />
<strong><em>Note</em></strong>: <em>this assumes you installed SharePoint on your C drive. Please change the install path if otherwise.</em></li>
<li>Enter the following: stsadm -o installfeature -name DemoMasterPage -force<br />
<strong><em>Note</em></strong><em>: do not copy and paste. Sometimes copy and paste into command lines won&#8217;t work. Please retype in your command line</em></li>
<li>Enter the following: stsadm -o activatefeature -name DemoMasterPage -url <a href="http://mysitecollectionpath/">http://mysitecollectionpath</a> -force<br />
<strong><em>Note</em></strong><em>: do not copy and paste. Sometimes copy and paste into command lines won&#8217;t work. Please retype in your command line</em></p>
<ul>
<li>The string after &#8220;name&#8221; is the name of feature of your feature folder.</li>
<li>The url is the url to your site collection root. You can copy it from your browser, but <span style="underline;">don&#8217;t</span> keep the &#8220;default.aspx&#8221; on the path</li>
</ul>
</li>
</ul>
</li>
</ol>
<p>What&#8217;s wrong with this picture?</p>
<p>Any developer will say this is not correct. Developers don&#8217;t want to copy files manually and paste them in a folder. Yes, I understand this. I am showing this technique to lead up to the last article in this series on solution deployment. The solution will take care of moving the files to the 12 hive and running the commands for you. However, it is important to understand what solutions do before jumping right into them. Thus, I am showing you this manual way so you can get an idea of what the solution is doing behind the scenes.</p>
<h2>Set the new master page</h2>
<p>The feature we just created placed the new master page in the master page gallery. However, it did not tell SharePoint to use this new master page on your SharePoint site. There are multiple ways to do this including: custom site definitions, programmatically setting the default master page, using SharePoint Designer, or using the MOSS master page selection page.</p>
<p>If you are using WSS, please refer to article 3 in this series <a href="http://sharepointmagazine.net/technical/customisation/developing-a-custom-master-page-master-pages-and-sharepoint-part-3-of-6">http://sharepointmagazine.net/technical/customisation/developing-a-custom-master-page-master-pages-and-sharepoint-part-3-of-6</a> in order to see how to set the master page in SharePoint designer.</p>
<p>If you are using MOSS, you can go to your site collection and then go to site settings. Then under &#8220;Look and Feel&#8221; click on the &#8220;Master Page&#8221; link. You can now choose the demomasterpage.master to be the master page for your site collection.</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="638" valign="top"><strong><em>Please Note</em></strong>: This assumes you have the Publishing feature turned on in MOSS. The Publishing feature might be turned on and might not be turned on based on the site definition you used to create your site. If the Publishing feature is not turned on in MOSS you will <span style="underline;">not</span> see the &#8220;Master Page&#8221; link under &#8220;Look and Feel&#8221; in the Site Settings page. To turn the Publishing feature on go to Site Settings, then look under the &#8220;Site Collection Administration&#8221; column and then click the &#8220;Site collection features&#8221; link. Find the &#8220;Office SharePoint Server Publishing Infrastructure&#8221; column and click Activate. Now, when you go back to the Site Settings &#8211; &#8220;Look and Feel&#8221; column you will see the &#8220;Master Page&#8221; link.</td>
</tr>
</tbody>
</table>
<p><a href="http://sharepointmagazine.net/wp-content/uploads/2008/10/mosspickdemocompanymaster.jpg"><img class="alignnone size-medium wp-image-1288" src="http://sharepointmagazine.net/wp-content/uploads/2008/10/mosspickdemocompanymaster-300x278.jpg" alt="" width="300" height="278" /></a></p>
<h2>Making Changes to the Master Page</h2>
<p>Now the Master Page has been installed to the SharePoint farm and activated on the site collection. So, what if you want to make further customizations to the master page? Do you have to go through the process of re-installing and re-activating? The answer is no. Here comes the power of ghosting. Please refer to article 3 <a href="http://sharepointmagazine.net/technical/customisation/developing-a-custom-master-page-master-pages-and-sharepoint-part-3-of-6">http://sharepointmagazine.net/technical/customisation/developing-a-custom-master-page-master-pages-and-sharepoint-part-3-of-6</a> for more information about Ghosting. Since the master page is ghosted, the SharePoint site keeps a reference to the 12 hive version of it. So, if you want to make a change to your master page, all you have to do is update the demomasterpage.master file in the feature folder of the 12 hive (%Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEA)TURES.</p>
<h2>Deactivating the Feature</h2>
<p>Sometimes there are changes you need to make to a feature that are not ghosted. Examples of these types of changes are things in the feature.xml file. You cannot change the id of a feature.xml file and expect to be able to just re-install and re-activate the feature. Instead, you have to deactivate the feature and uninstall the feature first. Here are the commands to do this.</p>
<ol>
<li>Open up a command prompt</li>
<li>Enter the following: cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN.<br />
<strong><em>Note</em></strong>: <em>this assumes you installed SharePoint on your C drive. Please change the install path if otherwise.</em></li>
<li>Enter the following: stsadm -o deactivatefeature -name DemoMasterPage -url <a href="http://mysitecollecitonpath/">http://mysitecollecitonpath</a> -force<br />
<strong><em>Note</em></strong><em>: do not copy and paste. Sometimes copy and paste into command lines won&#8217;t work. Please retype in your command line</em></li>
<li>Enter the following: stsadm -o uninstallfeature -name DemoMasterPage -force<br />
<strong><em>Note</em></strong><em>: do not copy and paste. Sometimes copy and paste into command lines won&#8217;t work. Please retype in your command line</em></li>
</ol>
<h2>Conclusion</h2>
<p>Using features to deploy the master page to the master page gallery is a reusable way to deploy master pages in SharePoint. However, there are still manual processes involved (including copying files to the 12 hive). Thus, using features is not the complete story when dealing with SharePoint deployments. In the last article in this series we will discuss SharePoint solutions (WSPs). WSPs are basically CAB files that wrap up features in SharePoint for easy deployment. The WSP file will move the feature files to the 12 hive for you. However, I think it is important to understand how this is done before jumping into creating WSP solutions. Plus, we can reuse the feature we created in this article when we build the WSP solution out in the final article of this series.</p>
]]></content:encoded>
			<wfw:commentRss>http://sharepointmagazine.net/technical/development/deploying-the-master-page/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>
