Compartilhar via


How to: Create a Custom Web Template

Applies to: SharePoint Foundation 2010

This topic provides a brief overview of how to create a custom web template.

To create the initial web template

  1. Users create a web template by saving a website "as template" in the user interface (UI). This is also the easiest way for you as a developer to begin. In the UI, create a website of a type that is most similar to the custom site type that you are creating.

  2. Add or delete lists, Web Parts, and other Features as needed until the website matches your idea for a custom site type as closely as possible using only the Microsoft SharePoint Foundation UI and Microsoft SharePoint Designer.

  3. When you have the prototype website as close as you can get it to your custom site type, save it as a template on the Site Settings page. The web template is saved to the site collection's Solution Gallery. Do not use spaces in the template name.

  4. If you need additional customization that cannot be done in the UI, follow the steps in the procedure "To set up a Visual Studio project."

To set up a Visual Studio project

  1. Deactivate the solution in the Solution Gallery.

  2. Download the solution (.wsp) file from the Solution Gallery.

  3. Delete the solution from the Solution Gallery.

    Note

    You can also write code to save a website as a template and download the solution package directly to the local file system, bypassing the Solution Gallery altogether. For an example, see the SPSolutionExporter.ExportWeb method.

  4. In Microsoft Visual Studio, create an Import SharePoint Solution Package project. Specify that the project is a sandboxed solution, not a farm solution.

  5. When you are prompted to specify the project source, specify the path to the solution that you downloaded.

  6. When you are prompted to select the items to import, select all the items or just the items that are needed, and then click Finish.

  7. When Visual Studio finishes creating the project, highlight the project name in Solution Explorer. In the Property window, set the Include Assembly in Package property to false.

  8. Edit the extracted files as needed. In most cases, you have to change only the WebTemplate element or the Onet.xml file. For more information, see the following procedures.

To edit the WebTemplate element

  1. In Solution Explorer, under the Web template node, there is a subfolder that contains an Elements.xml file. Open this file.

  2. Edit the WebTemplate child element of the Elements tag as needed. For information about the meaning of the attributes of the WebTemplate element, see WebTemplate Element (Web Template).

To edit the Onet.xml file

  1. The Onet.xml file for the web template is located either in the same subfolder as the Elements.xml file that contains the WebTemplate element, or in a subfolder in the Other Imported Files node in Solution Explorer. Open the Onet.xml file.

  2. Edit the Onet.xml file as needed. Editing this file is basically the same as editing an Onet.xml file that is part of a site definition. (For more information, see How to: Create a Custom Site Definition and Configuration.) But note these differences:

    • The Project element in a web template's Onet.xml file has only two child elements: the NavBars element and the Configurations element. The BaseTemplateID attribute and the BaseTemplateName attribute of the WebTemplate element identify the site definition from which the web template is ultimately derived. The Onet.xml file of the web template depends on the Onet.xml file of that source site definition for all other child elements of the Project element, including ListTemplates, DocumentTemplates, Modules, ServerEmailFooter, and Components.

    • The Configurations element has only one child Configuration element.

    • Some of the attributes of the WebTemplate element have the same name as attributes of the Project element. Use the attributes in the WebTemplate element.

    For more information about this file, see Understanding Onet.xml Files.

To package, upload, and test the custom web template

  1. In Visual Studio, on the Build menu, select Deploy Solution. If your development farm is a single-server farm, this builds the solution, repackages it, uploads it to the site collection's sandboxed solutions gallery, and activates it. If your development farm is multi-server, you must perform the activation step in the UI.

  2. Test the custom web template by creating a website from it.

See Also

Concepts

Web Template XML