Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
General Reference
Sites and Pages
Master Pages
 Customizing Master Pages in Windows...
Community Content
In this section
Statistics Annotations (9)
Customizing Master Pages in Windows SharePoint Services

When you install Windows SharePoint Services, a single default master page is applied to all the pages in a site. You can, however, create your own master pages for a site and make them available to the site and any sites beneath it.

There are two supported scenarios for customizing master pages in Windows SharePoint Services:

  • Copy the default.master file that is installed with Windows SharePoint Services to another file and make your changes to your renamed file.

  • Edit the default.master page in Microsoft Office SharePoint Designer 2007, where you can edit master pages, view master pages, create content pages, and view content pages with the master pages marked as masters and read-only.

    Office SharePoint Designer is the only application in which you can see a master page preview.

Caution Caution:

Do not edit the default.master file directly in the <%System Drive%>Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\GLOBAL\ folder.

When a new site is created, it uses the default master page that is located in the file system. If a master page is customized using Office SharePoint Designer, Windows SharePoint Services stores a modified version of the master page in the content database. Changes to the master page do not affect the content pages that refer to it; they remain in the file system.

Note Note:

Customization of the master page for a site changes only the content pages for that site. It does not affect application pages (pages in _layouts), because _layouts pages are pages of the Windows SharePoint Services application and are shared across sites.

Referencing the Master Page from a Content Page

Windows SharePoint Services provides several tokens to reference the master page—two dynamic tokens ("~masterurl/default.master" and "~masterurl/custom.master") and two static tokens ("~site/default.master" and "~sitecollection/default.master").

Note Note:

These tokens apply to Windows SharePoint Services master pages only; they do not apply to ASP.NET 2.0 master pages.

  • Dynamic token "~masterurl/default.master"

    This token references a master page from a content page by using the MasterPageFile attribute together with the value of the MasterUrl property. As an example, in the following page directive, <%@ Page MasterPageFile="~masterurl\default.master"%>, the token "~masterurl/default.master" is replaced at run time by the value in the MasterUrl property. This property contains the server-relative full path to the master page, including file name.

    At installation time, all SharePoint content pages use this dynamic token and the MasterUrl property is set to the Windows SharePoint Services default.master; however, you can change this value at any time to point to a different master page.

    Important Important:

    The entire string "~masterurl/default.master" comprises the token.

  • Dynamic token "~masterurl/custom.master"

    This token references a master page from a content page by using the MasterPageFile attribute with the value of the CustomMasterUrl property. The token "~masterurl/custom.master" is replaced at run time by the value in the CustomMasterUrl property, which contains the server-relative full path to the master page, including file name.

    This token is not used by any SharePoint content pages by default, and is provided as a way to have a second shared master page.

    Important Important:

    The entire string "~masterurl/custom.master" comprises the token.

  • Static tokens "~site/default.master" and "~sitecollection/default.master"

    You can use these tokens to link to a site-relative or site collection-relative master page. For example, if your content page is located at http://siteColl/subsite1/subsite2/default.aspx and you use the token "~sitecollection/mypage.master", your content page would use the master page at http://siteColl/mypage.master. If you use the token "~site/mypage.master", the content page would use the master page located at http://siteColl/subsite1/subsite2/mypage.master.

Note Note:

The MasterUrl and CustomMasterUrl properties are both set to "/_catalogs/masterpage/default.master" by default. If you subsequently need to delete default.master, you must set both of those properties to a different value, not just one of them, or an error is raised that suggests the default.master file is still being used as the master page for the site.

Alternatively, you can change the master page used by a content page by directly changing the URL for the MasterPageFile attribute specified in the page directive. Unlike using the MasterUrl property to change a master page, however, this is a change to the page's content.

Additional Considerations for Working with Master Pages in Windows SharePoint Services

Consider the following when you are working with master pages in Windows SharePoint Services:

  • Compilation mode for master pages works like the compilation mode for any other .aspx page. You can change the compilation mode at any time, and you can combine compilation modes for master and content pages, for example, a compiled master page and a content page that is not compiled.

    Remember, however, that although compiled master pages can contain inline script, after that page is customized in Office SharePoint Designer, or a similar tool, the page is no longer compiled and script no longer runs. For that reason, it is recommended that you do not include inline script in your master pages.

  • Although the underlying technology enables the creation of nested master pages, nested master pages are not supported in Windows SharePoint Services.  Using nested master pages can cause unexpected behavior in some scenarios, such as preventing content from rendering.

    Note Note:

    Some page editors may not effectively support nested master pages.

  • You cannot add Web Parts in zones to a master page. You can add static Web Parts (parts outside of a zone) to a master page, but you cannot add dynamic Web Parts to master pages.

    You can add zones to master pages and later add Web Parts to the zone in the browser, but the Web Parts are associated with the content page.

See Also

Community Content   What is Community Content?
Add new content RSS  Annotations
Default for MasterURL and CustomMasterURL.      DMDJ   |   Edit   |   Show History
The MasterUrl and CustomMasterUrl properties are both set to "/_catalogs/masterpage/default.master" relative to the current site by default.
Tags What's this?: Add a tag
Flag as ContentBug
sitecollection does not work      User77   |   Edit   |   Show History

The token "~sitecollection/default.master" didn't work. I had to use "~sitecollection/_catalogs/masterpage/default.master". To get http://siteColl/subsite1/subsite2/default.aspx.

Tags What's this?: Add a tag
Flag as ContentBug
Nested Master Page Directive      arriba   |   Edit   |   Show History

To reference one master page from another master page use:

<%@ Master language="C#" MasterPageFile="Parent.master"%>

instead of <%@ Master master=MyParent.master %>

Tags What's this?: Add a tag
Flag as ContentBug
I edit the default.master and error ...      Raja_Mohamed   |   Edit   |   Show History

I edit the default.master file directly in the <%System Drive%>Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\GLOBAL\ folder. And then I can't connect into my collection site. So I restaured the file and the error is still there !
This is the error message : Une erreur est survenue lors du traitement de /_catalogs/masterpage/default.master. The resource object with key 'treeview_hea?er' was not found.

UI issue (Example master pages and custom form)      MRizwanAhmed   |   Edit   |   Show History
I have implemented the custom task edit form for a custom workflow and get
all fuctinality working well.

but when I change my master page from default one to newly added Windows
SharePoint Services 3.0 Sample: Example Master
Pages(block_lay4_orange.master)from microsoft The UI becomes dirty and all
controls are missplaced. Though I have published(Approved) All pages .
(its urgent)
Please help me
Tags What's this?: master (x) page (x) Add a tag
Flag as ContentBug
You can NOT add web part zones to Master Pages      Andy Burns   |   Edit   |   Show History

Contrary to the last bullet point on the page, you can not add web part zones to Master Pages. SharePoint designer won't let you, and if you go ahead and code one by hand, when you try and use the page you'll get a parser error.

Tags What's this?: master (x) page (x) part (x) web (x) zone (x) Add a tag
Flag as ContentBug
Okay, but when I use Microsoft's Master Page templates.......      rdparris   |   Edit   |   Show History
Okay, but when I use Microsoft's Master Page templates, the content/webparts all show up on the site......but will not print or even show in print preview. This is regardless of content [calendar, list, etc.], and regardless of browser. It's something with the Masterpage. Anyone else having this same problem?
Tags What's this?: Add a tag
Flag as ContentBug
Master Page Samples Do Not Print      Bill Hennessy   |   Edit   |   Show History
I have the same problem as rdparris describes. Only the page header shows up in print preview and printed pages once I made a Microsoft Master Page Sample file the default page. Any idea where I go to fix this?
Flag as ContentBug
Fixed Printing Problem in Sample Master Pages      Bill Hennessy   |   Edit   |   Show History
Add this to the end of the master style sheet (template_layout.css):

@media print
{
.ms-leftareacell{
display:block;
}
.ms-rightareacell, .ms-titleareaframe{
display:none;
}
.ms-nav{
display:none;
width:0px;
}
.ms-bodyareacell{
left:0px;
margin-left:0px;
float:none;
width:100%;
}
}

It worked for me.

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker