Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How can I create a custom web template in Visual Studio?

See here some requirements: I dont want to create a site definition! I dont want to import a saved template file (wsp) into Visual Studio

I think, but not sure it is something like this:

1)Create a new SharePoint project

2)Create a new empty elements.xml file

3)Find the onet.xml from the publish site tempalte in the 14 hive folders

4)Copy the xml code inside this file

5)Paste the xml code in the elements.xml file you created in step 2

6)At this point you have a clean custom web template which is equal to the publish site template

7)Now you can add or remove stuff to your custom template

The reason why I ask you in this forum, is because I cannot find anything in google or youtube. There is alot info about site definions, but thats not what I am looking for. I am looking for how to create a custom web template in VS.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

somthing like this?

http://msdn.microsoft.com/en-gb/library/ff408263(v=office.14).aspx

or i think your talking about this:

Create SharePoint Project

1.Open Visual Studio 2010

2.Click File -> New -> Project

3.Select “Empty SharePoint Project” under SharePoint -> 2010 category.

4.Enter Name for the project e.g. SampleWebTemplate.

5.Click OK.

6.Select “Deploy as a sandboxed solution” in next window.

7.Ensure local site is your targeted site.

8.Click “Finish“

Create Element with Feature

1.Right click on project (i.e. SampleWebTemplate) points to “Add” and click “New Item“

2.Select “Empty Element” under SharePoint -> 2010 category and name it to SWTSite (Sample Web Template Site)

3.Above step will create a SharePoint element (Elements.xml) with a feature associated with it.

4.Newly created feature name is “Feature1”, we must rename it and name it same as Element name (i.e. SWTSite) otherwise we must change DeploymentLocation in onet.xml.

5.To rename feature, Click on feature1 and Press F2.

6.Change feature name from Feature1 to “SWTSite”

7.Open “Elements.xml” Now we need to add few tags in it as shown below.

8.Add element “WebTemplate”. WebTemplate element has four mandatory attributes, Name (Internal name of site template), BaseTemplateID, BaseTemplateName and BaseConfigurationID are used to define base template on which new template is based on.

9.Title and DisplayCategory are used for ease. DisplayCategory is tab name under which template will be visible.

10.Now “Elements.xml” will look like this.

<?xml version=“1.0“ encoding=“utf-8“?>

<Elements xmlns=“http://schemas.microsoft.com/sharepoint/“>

  <WebTemplate Name=“SWTSite“

               Title=“Sample Web Template Site“

               BaseTemplateID=“1“

               BaseTemplateName=“STS“

               BaseConfigurationID=“0“

               DisplayCategory=“SWT sites“ />

</Elements>

11.New Web Template is based on an existing web template (which is STS template).

12.Now we need to copy template’s files and modify them to change whatever in the template. In this example we will not change anything but just re-use the template as is.

13.Open “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\SiteTemplates\sts” folder

14.Copy both “default.aspx” and “defaultdws.aspx” into your project folder.

15.Copy “ONET.xml” from “sts\xml” folder to your project folder also.

16.Right click on Element(i.e. SWTSite) points to “Add” and click “Existing Item“

17.Select all three files that you copied before (default.aspx, defaultdws.aspx and onet.xml) and press “Add”

18.Make some changes in feature we must set feature Scope to Farm to be able to do this.

19.Right-click on SWTSite feature and click “View Designer”

20.Change Scope to “Farm”

21.Change Title/Add description of the feature if you would like to, this will appear under farm features.

22.As an example change title to “SWTSite Feature” and add description “This feature will add new web template based on STS template.”

23.Important! Make sure three files (default.aspx, defaultdws.aspx and onet.xml) that we added before are also included in deployment.

24.To ensure this, Click on the file one by one and select Development Type as “ElementFile” whereas Elements.xml will be of type “ElementManifest”

25.Make sure you mark Sandboxed Solution to FALSE in project properties because sandboxed solution cannot be deployed at Farm level.

26.Deploy your solution. If successfully deployed go ahead otherwise, look through all steps above if you missed something. If you encountered with something un-addressed, please write it in comments so I can update the post and make it more useful for others.

27.Create new site collection and apply new template.

http://usmanmughal.wordpress.com/2011/04/26/how-to-create-web-template-in-sharepoint-2010-using-feature/

share|improve this answer
    
Thanks ali SharePoint. What a great answer!!! –  KHA Mar 26 '13 at 19:08
    
no probs happy to help! –  ali Sharepoint Mar 26 '13 at 20:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.