How to create your own master page ,Include a example
最近在做sharepoint项目.项目中要求使用custome master page.于是就在网上找了很多资料.通过资料我们可以知道有两种方式制作masterpage,一种是通过sharepoint designer来开发(好像不便于deploy),另一种是通过feature.我们这里讲通过Feature的方式发布Masterpage.
Solutions:
1.First you can create a minimal master page Just includes all the share point server 2007 page model content placeholders (a empty master page can’t work well)
The following procedure includes all the basic content placeholders ,layouts ,controls that share point server 2007 can work .A default master page includes a title, branding ,logon functionality ,search functionality ,breadcrumb functionality ,and basic structural elements such as page areas ,separators ,borders ,consoles and description placeholders .
The master pages included with Office SharePoint Server 2007 are based on the SPWeb.CustomMasterUrl property of the SPWeb class in Windows SharePoint Services.
To create a minimal master page
1. Open SharePoint Designer.
2. On the File menu, click New, point to SharePoint Content, and then click the Page tab.
3. Double-click Master Page to create a new master page.
4. Click Design to show the master page in design view. You should see header and left margin areas and several content placeholders in the master page.
5. Click Code to show the master page in code view.
6. Copy the following code into the master page.
Xml
7. On the File menu, click Save As, provide a unique file name with the .master
extension, and then save the file to the master page gallery (/_catalogs/masterpage
) in your site collection.
Follow this article you can work out a master page
This article refers to Microsoft Office SharePoint Server 2007 (MOSS 2007) Beta 2 Tech Refresh. Details are subject to change in the RTM version.
One way master pages can be stored and used in MOSS 2007 sites is through creation in SharePoint Designer and storage in the Master Page Gallery. This method will create a master page in the content database. But what if you need to use one or two master page across multiple site collections? For ease of updates and maintenance, we don't necessarily want to store a copy of the master page in each site collection. Instead we can create and store master pages on the file system as a SharePoint Feature and make it available for new and existing site collections.
If for some reason you don't want to create a custom Feature, you can manually work through this process by editing the default Publishing Layouts Feature that ships with SharePoint. See this article here for instructions.
A huge thanks to my friend Andrew Connell for showing me the light on how to accomplish this with a custom feature. His help was invaluable.
Create a Feature: Add Custom Master Pages to your Site Collections
- Navigate to the Features directory on your web server:
Local Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES - Locate the PublishingLayouts Feature directory. Copy this folder and paste it at the root of Features. Rename the folder to a unique name of your choice. For my example I used CustomMasterPages.
- Open your new Feature directory. At this point you can leave all the default folders, or you can choose to clear out what you don't want to use. You only have to keep Feature.xml and ProvisionedFiles.xml. To create a clean file set, at a minimum clear out the contents of each sub folder in the directory (en-us (or your language), Images, MasterPages, PageLayouts, Styles).
- To start, we need at least one master page file in the Feature folder. You can copy one of the existing master pages, paste the copy in the directory, and rename the copy to your unique name, or alternately paste in your custom master page, or create a new blank file with the extension of .master.
Tip! To just get a master page going, copy the sample code from this article and paste it in your custom master page file. That will get you up and running for this article and give you a good starting point for your customizations once the master page has been applied to your site. If you do this, after pasting the code into your master page file, locate this line of code and add a missing quotation mark: <asp:ContentPlaceHolder id="PlaceHolderTitleBreadcrumb" runat="server"/> - Next, open the ProvisionedFiles.xml file in Notepad or a similar editing application.
Local Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\YourFeature - We are going to delete out all of the content and only keep the OSGMasterPages Module tag and the PublishingLayoutsPreviewImages Module tag. As opposed to listing out what to strip out, here is the code you need in this file:
<!-- _lcid="1033" _version="12.0.4407" _dal="1" -->
<!-- _LocalBinding -->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="OSGMasterPages" Url="_catalogs/masterpage" Path="MasterPages" RootWebOnly="TRUE">
<File Url="Sample.master" Type="GhostableInLibrary">
<Property Name="ContentType" Value="My Sample Master Page" />
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/sample.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/sample.png" />
<Property Name="MasterPageDescription" Value="This is my sample master page for use with collaboration or publishing sites." />
</File>
</Module>
<Module Name="PublishingLayoutsPreviewImages" Url="_catalogs/masterpage" IncludeFolders="??-??" Path="" RootWebOnly="TRUE">
<File Url="Sample.png" Name="Preview Images/Sample.png" Type="GhostableInLibrary">
</File>
</Module>
</Elements> - Update the properties to reflect the new master page details:
- Change the URL to your custom master page.:
<File Url="Sample.master" Type="GhostableInLibrary"> - Change the Preview Images to a custom image:
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/Sample.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/Sample.png" />
Add the custom image to the following directory:
Local Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\PublishingLayouts\en-us - Update the Description. Enter a description for your master page:
<Property Name="MasterPageDescription" Value="This is my sample master page for use with collaboration or publishing sites." /> - Update the image names:
<File Url="Sample.png" Name="Preview Images/Sample.png" Type="GhostableInLibrary">
- Change the URL to your custom master page.:
- Save the ProvisionedFiles.xml file.
- Create a preview image in the language folder (in this case, en-us).
- Next, open the Feature.xml file in Notepad or a similar editing application.
Local Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\YourFeature - There are four things you need to edit in this file:
- Change the Feature ID to a unique GUID. You can generate GUIDs in Visual Studio (Tools - Create GUID - Registry Format - Copy). Paste the new GUID for the ID and remove the curly brackets.
<Feature Id="FDFCD4C4-F0D9-43b5-8739-A33681049657" - Update the title:
Title="Custom Master Pages" - Update the description:
Description="Custom master pages for use across multiple site collections." - Change the Hidden state to False:
Hidden="False"
- Change the Feature ID to a unique GUID. You can generate GUIDs in Visual Studio (Tools - Create GUID - Registry Format - Copy). Paste the new GUID for the ID and remove the curly brackets.
- Save the Feature.xml file.
- Recycle the Application Pool for the site you plan to install the Feature on, or reset IIS (Command Prompt - IISRESET).
- You are now ready to install the new Feature on the web server. Open a Command Prompt and enter the following:
- Change directories to the BIN folder in the 12 hive so you can use STSADM.exe:
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN - Launch STSADM and install the feature:
stsadm -o installfeature -name YourFeatureDirectoryName
- Change directories to the BIN folder in the 12 hive so you can use STSADM.exe:
- Now we will activate the feature on the site.
- Open your site and navigate to the Site Collection Features settings page. Site Actions - Site Settings - Modify All Site Settings - Site Collection Features (under the Site Collection Administration submenu).
- The new feature will be listed:
- Select Activate.
- The master pages are now ready to use on the site. Navigate to the Master Page settings by selecting Site Settings in the breadcrumbs and choosing Master Page. (Or Site Actions - Site Settings - Modify All Site Settings - Master page (under the Look and Feel submenu).
- Depending on your requirements, in either or both the Site Master Page setting and the System Master Page setting, select your drop down box and choose your custom master page.
- Select OK.
- The master page is applied to the site. Note that I manually added the "Sample Master Page" text to the Sample.master file. It will not appear on yours by default.
Adding to our Feature: Adding More Custom Master Pages to your Feature
If you ever need to add new master pages to this feature, you can edit the Feature and redeploy it. Alternately, you can create a new Feature for each custom master page. For that scenario, just follow the steps above for creating a new feature. The following outlines how to update your Feature with new master pages.
- Navigate to your custom master page Feature directory and add the appropriate files for your new master pages.
- Navigate to and open the ProvisionedFiles.xml file. Add a FILE tag block for each new master page for both the OSGMasterPages Module and the PublishingLayoutPreviewImages Module. Save the file.
- Recycle the Application Pool for the site you plan to install the Feature on, or reset IIS (Command Prompt - IISRESET).
- You are now ready to reinstall the updated Feature on the web server. Open a Command Prompt and enter the following:
- Change directories to the BIN folder in the 12 hive so you can use STSADM.exe:
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN - Launch STSADM and install the feature:
stsadm -o installfeature -name YourFeatureDirectoryName -force
- Change directories to the BIN folder in the 12 hive so you can use STSADM.exe:
- Now we will deactivate and reactivate the feature on the site.
- Open your site and navigate to the Site Collection Features settings page. Site Actions - Site Settings - Modify All Site Settings - Site Collection Features (under the Site Collection Administration submenu).
- Your existing feature will be listed:
- Select Deactivate.
- A warning message will appear. Select Deactivate the feature.
- The Feature list will reload. Select Activate next to your custom feature.
- Your new master pages are ready for use.
Use the following cmd to install and uninstall
stsadm –o installfeature –name yourfolder name (AACustomeMasterPage)
stsadm –o uninstallfeature –name yourfolder name (AACustomeMasterPage)
I do a example you can find it
参考
1:How to create your own master page ,Include a example.
http://www.heathersolomon.com/blog/archive/2007/01/26/6153.aspx
http://msdn.microsoft.com/en-us/library/aa660698.aspx
http://www.heathersolomon.com/blog/articles/servermstpageforsitecollect_feature.aspx
http://msdn.microsoft.com/en-us/library/ms476046.aspx
Microsoft Website
http://msdn.microsoft.com/en-us/library/bb727372.aspx
SharePoint Magazine
http://sharepointmagazine.net/technical/customisation/developing-a-custom-master-page-master-pages-and-sharepoint-part-3-of-6
http://www.mindsharpblogs.com/PaulS/archive/2007/06/18/1903.aspx