How to: Import a Master Page or Theme

Master pages and themes can give pages on a SharePoint site a consistent appearance. Although Visual Studio does not provide templates for master pages or themes, you can create them in SharePoint Designer and then import them into Visual Studio. This document shows how to import master pages and themes. For more information, see Building Block: Pages and User Interface on the MSDN Web site.

To import a master page or theme

  1. Open a SharePoint project in Visual Studio.

    If you do not have a project, you can create an Empty SharePoint Project. For more information, see SharePoint Project and Project Item Templates.

  2. In Solution Explorer, right-click the project node, point to Add, and then click New Item.

  3. In the Add New Item dialog box, in the list of SharePoint templates, select Module. Give the module a name.

    A module is used as a container to deploy files, for example, master page or theme files, to a specified location in SharePoint.

  4. In the module, delete the default Sample.txt file.

  5. To add the master page or theme file to the module, select the module node and then, on the Project menu, click Add Existing Item. Locate the master page or theme file and select it. Master page files have a .master file name extension and theme files have a .thmx file name extension.

  6. If you added a master page, change its Deployment Conflict Resolution setting to Automatic.

    NoteNote

    If the name of the master page is the same as the name of an existing master page that is marked as either Default Master Page or Custom Master Page, errors can occur. For information about how to resolve this problem, see Walkthrough: Import a Custom Master Page and Site Page with an Image.

  7. In the module, double-click Elements.xml to open it in the editor.

    You must update the Elements.xml file to reference the master page or theme that you added.

  8. For a master page, replace the existing module markup with the following markup.

    <Module Name="[Module Name]" Url="_catalogs/masterpage">
        <File Path="[Module Name]\[Master Page Name].master" 
          Url="[Master Page Name].master" Type="GhostableInLibrary" />
    </Module>
    

    For a theme, replace the existing module markup with the following markup.

    <Module Name="[Module Name]" Url="_catalogs/theme" 
        <File Path="[Module Name]\[Theme Name].thmx" Url="[Theme   
          Name].thmx" Type="GhostableInLibrary" />
    </Module>
    

    Be sure to replace the placeholder values with the actual names of the module and the master page or theme.

    The attribute Type="GhostableInLibrary" indicates that the item is added to the content database, and the Url attribute of the module specifies where to store the file in the SharePoint content database.

  9. To change the deployment scope for the master page, in Solution Explorer, double-click the feature file to view it in the Feature Designer.

  10. Click the Scope box to specify the scope for the master page.

    A value of Web means that the master page applies only to the Web site that is currently specified in the project. A value of Site means that the master page applies to the current site collection; this includes all subsites and the root Web. The other values do not apply.

    NoteNote

    Because themes apply only to the site collection level, we recommend that you do not set the scope of a theme to anything other than Site. Errors can occur if a theme is used in a sub-site.

  11. On the Build menu, click Deploy Solution.

  12. To verify that the files were deployed correctly, open the SharePoint site.

  13. On the Site Actions tab in SharePoint, click Site Settings.

  14. If you added a master page, on the Site Settings page, click Master pages to view the list of master pages. If you added a theme, on the Site Settings page, click Themes to view the list of themes. The imported master page or theme should appear in the list.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft