First off, I should state that there’s really no such thing as a site collection template. What happens when a new site collection is created is that the collection gets created, and then a web template is applied to the root site. This whole process is actually decoupled in SharePoint 2010, and you no longer need to select a template when the site collection is created (). Todd has a very clever solution to getting your web template to be used at the root site, but I recently had a requirement to have it fully automated, and to be visible to the templates available when creating a site collection in Central admin. This was relatively straightforward in SharePoint 2007, you would save a particular site as a template, then go to the template gallery, download it to the file system on a front end server, and then to have it added to the Site definitions list. However, in SharePoint 2010, site templates are no longer.STP files,they use.WSP solutions in the user solution gallery. That should be easy,right? Just save off the WSP file, add the solution to the farm with either PowerShell or STSADM. The solution will actually install, but your site template won’t show up. The main reason is that the actual web template is scoped to “web” and for it to show up for site collections, it needs to be scoped for the farm. The good news is that you can import a WSP file directly into Visual Studio 2010, edit it, and create a new solution that does work. I will now attempt to describe the relevant steps, and a few gotchas to do this. Save The Site as a Template Once you have your site looking and behaving the way that you want, it’s time to save it off. Select Site Settings, and click Save Site As Template – It’s under the Site Actions section. Give the template a file name, name, and if desired, a description. Once you select OK, the solution will be created and saved to the solution gallery, which is at the root of the site collection. You’ll want to go there next, and you can do so by clicking on the “solution gallery” link in the successful save confirmation page, or by navigating to the root of the site collection, then selecting Site Actions – Site Settings and clicking on the Solutions Gallery link. There is no more Site Template Gallery!!! Save the WSP File Locally From the solutions gallery, Click the name of your solution, and you will be prompted to save the wsp file. ![]() Make sure the URL you choose to deploy the solution to actually points to an existing SharePoint site on the machine you are working on. RIght-click on the project name in the solution explorer and select Add > New Item. Now open up the ONET.xml file to clean it up. Now go back to Site Actions and choose New Site. Apr 25, 2011 Web Templates are introduced in SharePoint 2010 mainly to define site definition as sandboxed solutions. You can create a web template in following manner. 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. 50 rows SharePoint 2010: Default Site Templates. What is a SharePoint site. Go ahead and do that, and then you need to delete the template from the gallery. You’ll be ultimately registering it in the farm, and you don’t need any confusion as to which template to choose. As well, if you’ll be using the same name, this will lead to conflicts, so it’s best to eliminate it altogether. Create a Project in Visual Studio Open Visual Studio and create a new project. Make sure that you have the SharePoint 2010 Templates showing, and then select the “Import SharePoint Solution Package” template. From the next screen select “Deploy As a Farm Solution”, and click Next. Next, click Browse and navigate to the WSP file downloaded in 2. Finally, ensure that all of the included items are selected, and select Finish. Visual Studio will then import all of the items into the project. Now we’re ready to modify the project. Modify The Feature Definitions There will typically be 4 Features created for a site template, aptly named Feature1 through Feature 4. Personally, I like my feature names to be a little more descriptive than that. Feature 1 is for List Instances, Feature 2 is for Modules, Feature 3 is for the template itself, and Feature 4 is for the PropertyBag. The purpose of our solution is to make the site template available, and the other features are effectively there in a supporting role. Currently, all 4 features are scoped to web, and all 4 are visible. In addition to renaming them, we want to hide features 1,2, and 4 from display, and we want to scope feature 3 to the farm. First, we’ll modify the Feature name. Simply Single Click (or right click and rename) on the Feature in the Visual Studio Solution Explorer, and enter a new name. ![]() You’ll notice that all of the supporting elements below are automatically renamed as well. Next, We’ll want to modify the Title of the features. The title is what is used when the feature is displayed in the feature list. Although we’ll be hiding 3 of them, it’s still a good idea to use a descriptive title. Double click on the feature, and the Feature Definition box will open in the main window. Modify the Title, and if desired the Description field to something meaningful to your users. Go ahead and repeat this step for all of the 4 features With the feature definition in the main window, the feature properties should be loaded in the properties toolbox (if you don’t have it open, open it). We want to set the Is Hidden property to true for all of the features except for the Web Template feature itself (Feature 3). The web template feature itself requires an additional modification, we need to change the scope from site to farm. We can do this in either the properties window or the feature definition window, but the feature definition window is a little more obvious. Modify the Template Definition Itself. This step may not be required if the template name and title will be identical to that which was saved initially. However, in this case, we have called the solution Sample 1, and when the template was saved, it was MyCustomSite. We need to modify the template itself to be called Sample 1, and we may have some additional tweaks. From the Solution Explorer, open the Web Templates Folder and change the name of the Template by single, or right clicking on it. The feature definitions will be updated automatically. Next, we need to open the Elements.xml file, and change the Name and the Title tag to the new name. Search and replace is a good idea here. Next, open the ONet.xml and change the Title attribute in the Project tag to an appropriate value, in this case, Sample 1. This file can also be used to remove any feature dependencies that may not exist in the destination farm, but be careful – other elements of your template may be reliant on them. Test the Project Click on the Debug start button in Visual Studio and your template will be deployed to the server, and you’ll be prompted to create a new subsite. If you see your template in the custom tab, all is well. Go ahead and create a test site to make sure that everything is working. Visual studio may prompt you with deployment conflicts, just let it go ahead and resolve them automatically. Deploy the Solution We are now ready to deploy the solution to the farm. First, set Visual Studio to Release mode from the toolbar: Then, Right Click on the project, and select Package Then, you’ll need to navigate to your Visual Studio project folder, and then into the BINRelease folder. There you will find a.WSP file with the name of your project. You can either work with the file in place, or copy it to a folder, but next we will add the project to the Farm solution gallery. To do this, we will either use STSADM (old school) or PowerShell (the cool new way). I’m old, so I still use STSADM for solutions, but I’ll show both. To add the solution using stsadm.exe, open up a command prompt (in administrator mode if UAC is turned on), and navigate to the folder containing the solution file. The syntax is: C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14BINstsadm.exe –o addsolution –filename sample1.wsp Where sample1.wsp is the name of your solution file. To use PowerShell, open the SharePoint 2010 Management Shell, and enter: add-SPsolution –LiteralPath c:solutionssample1.wsp The argument for LiteralPath is the complete path to the solution file. If there are and spaces in the path name, it needs to be encased in quotes. Deploy the Solution Now that the solution has been added, it needs to be deployed. To do so, start central admin, Go to System Settings, and select Manage farm solutions in the Farm Management Section: Click on your solution name, and then click the Deploy Solution button. Click the OK button on the following screen, and your solution will be deployed. You can control whether or not the template is available by turning off the farm feature. You can do that from central admin by navigating to System Settings – Manage Farm Features. From here, you can turn your template on and off. Create New Site Collection At this point, we should be good to go. From Central Administration, navigate to Application Management, and click Create Site Collections. On the create screen, give the new collection a title, and a URL. Then, in the Template Selection, click the Custom tab, and your template should appear there. Give it a site collection administrator, and click OK. After a few moments, the site will be created, and you can navigate to it. Simple, right? Well, Microsoft giveth and Microsoft taketh away. Adding the template to the farm is considerably more involved with 2010 than with 2007. However this approach is also a great deal more flexible – you can tweak that template to your heart’s content, and if you have ever tried to create a site template with 2007 using Visual Studio, you can really appreciate how Visual Studio 2010 makes it significantly easier. 31 thoughts on “ How to Build a Site Collection Template from A Web Template in SharePoint 2010” • Brad Covell Thanks, Excellent. Exactly what I wanted to do and it works. Question: when I debug it or deploy it from Visual Studio I get a message about deployment conflicts, I automatically have VS resolve them but the deployment and/or debug fails and I””m asked to continue, if I continue to debug it works fine. Do I need to be concerned about these deployment conflicts? What is happening? When I package and deploy, it works great. • Pingback: • Sandra Hi, i have site collections (blank template) that use default.aspx for the home page. For new site collections i wanted to use custom site template and i created one like you described. The problem occured when i deployed my solution – all the default.aspx from my existing site collections got replaced with the one from solution. I created my custom site template from blank template and team template, but in both cases the results were the same. Is this the expected behavior? Because of my branding i have to have custom default.aspx. • Pingback: • Marco I don’t know what I’m doing wrong but this example simply is not working for me. During deployment I’m getting conflicts, chosing to resolve them automatically and this step fails. I have tried the simplest configuration: I’ve saved Team Site as a template, saved.wsp to file, deactivated and removed it, loaded into VS with success (and no errors) – and tried to deploy to another web application. Got conflicts, tried to resolve them automatically – got many messages in output window: “can not delete file” for many conflicted files. And deploy failed. Any help I appreciate very much. One of my coworkers,, recently asked me if it was possible to create a new Site Collection in SharePoint 2010 and use a custom site template for it. I'm usually more of a server and infrastructure guy, but this made me curious. In SharePoint 2007 site (really web) templates were saved as.STP files. Those STP files could be in the site collection gallery, or the farm gallery. If it was in the farm gallery then it was available at site collection creation. In SharePoint 2010 site (really web) templates are stored as user solutions in the site collection solution store as WSP files. Those WSP files don't upload at the farm level (at least not that I've been able to find). So how does one create a new site collection with a custom template? Stick around, we're going to find out. J The first thing to keep in mind is that site collections don't have templates, webs do. When a new site collection is created there is a template picker. That doesn't apply a template to the site collection itself, but to the rootweb of that site collection. When the site collection is created, the rootweb is also created. That is where the template is applied. Knowing that, we can figure out a solution. We know that the site collection gets created, with or without a template. If the site collection is created, then so is its solution gallery. If we upload our WSP to that solution gallery, then it's available to us when we create the rootweb. That's how we create a site collection with a custom template. Here's the blow-by-blow on how to do it. First we'll save out our site (really web) template. Start by going to the site you want to save as a template. Then go to Site Actions > Site Settings. It will look like this: When you click 'Save site as template' you see this screen (though it won't be filled out, you have to do that) If things go well, you'll get this screen. Click the link to go to the Solution Gallery. That should take you to this page: Click the name of the template you created. You'll be greated with this dialog to save it to your local file system: Now go into Central Administration and create the Site Collection (Application Management > Create site collections) you want to apply this template to. On the creation page go to the custom template page like below: The secret sauce is not selecting a template for the rootweb. When the site collection is created, you'll be given a link to it. When you click it you'll be taken to the template picker page, if you hit it as one of the site collection administrators. At the bottom is a link to your newly created site collection's solution gallery. Upload the template solution here: Don't forget to activate it. When you're back to the solution gallery use the breadcrumb to get back to the rootweb of the Site Collection: That will take you back to the template picker page. Now on the Custom tab we have our template. That's all there is to it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
April 2018
Categories |