How to Deploy a Site Taxonomy in SharePoint 2010

Sometimes we need to modify the out-of-the-box templates to deploy an entire site hierarchy based on the designed architecture. There situations require a code-based approach; many times we can simply create our site template modifications in SharePoint's graphical user interface and then deploy the site hierarchy with a PowerShell script, avoiding the more complex development and code lifecycle issues.

In this article helps to accomplish the following tasks

  1.  Create and configure a Web template in the SharePoint graphical user interface.
  2.  Modify and deploy the template for global use on the farm.
  3.  Create and execute a PowerShell script to deploy a hierarchy of sites.

Create and Configure a Web Template

  1. Go to your web application
  2. From the Site Actions menu, click New Site.
  3. Choose the Team Site template, fill in the site Title and URL and click Create.
  4. In your new site, in the left Quick Launch navigation, click Shared Documents.
  5. In the Ribbon, click the Library tab; then click the button labeled Library Settings.
  6. Click Version Settings.
  7. Change the Document Version Settings to Create Major and Minor (Draft) Versions.
  8. Set the Require Check Out setting to Yes.
  9. Click OK.
  10. In the left Quick Launch navigation, click Shared Documents.
  11. Upload a file or two to this library.
  12. Make other changes to list/library settings, and add other content to other places within the site.
  13. From the Site Actions menu, click Site Settings.
  14. In the Site Actions group, click Save Site as Template.
  15. Set the file name and template name to Demo, and ensure the Include Content box is checked.
  16. Click OK.
  17. When the template has been captured successfully, click the Solutions Gallery link that appears on the success confirmation page.
  18. Open another browser window and navigate to your Central Administration site. Click Create Site Collections under the Application Management group. In the Template Selection area, click through all the tabs. You notice that your Demo template is not listed and therefore not available for use outside the site collection in which it was created. The next section solves this issue.

Modify and Deploy a Web Template for Global Farm Use

The web template created above has been deployed to the site collection sandbox solution gallery. This means that it can now create new sites within that site collection only. But our aim is to build a hierarchy of sites in a new site collection, modify the web template in Visual Studio and deploy it to the farm.

  1. Navigate there by going to Site Settings (from the Site Actions menu) and then from theGalleries group, click Solutions.
  2. You should see the template that you created above. Click its name, and you will be prompted to download a .wsp file.
  3. Open Visual Studio by opening your Start Menu and selecting the Microsoft Visual Studio 2010 icon.
  4. From the Start Page in Visual Studio, on the left side click New Project.
  5. In the left list, expand the SharePoint node, and choose 2010. In the right list, choose the Import SharePoint Solution Package template.   
    In the Name text box, type TemplateDemo as the name for your new Visual Studio Project. See the following screenshot for guidance.

    p1.png

  6. Click OK. In the SharePoint Customization Wizard that follows, ensure that the local debugging site is pointed at your local SharePoint URL and change the trust level for your solution to Deploy as a Farm Solution. Click Next.
  7. When prompted for the path to the existing solution package, use the Browse button to navigate to the WSP file we saved in step 1. Click next.
  8. Ensure that all items are selected for import; then click Finish.
  9. In the Solution Explorer, find the four features that are labeled Feature1, Feature2, Feature3, and
    Feature4. (See the image on the right.) Right-click on each one and choose Rename. Rename them as follows:

    p2.png

    a. Feature1 ->ListInstances
    b. Feature2 -> Modules
    c. Feature3 ->WebTemplate

    d.Feature4 ->PropertyBag

  10. If the Properties window is not visible, turn it on by opening the View menu in the main toolbar, and choose Properties Window (toward the bottom).
  11. Expand the feature that is now labeled ListInstance, and double-click the ListInstances.Feature node as shown here.

    p7.png

  12. In the Properties window, change the Is Hidden property to True, as shown in the screenshot to the right. Repeat this process for the Modules and PropertyBag features as well (but not the WebTemplate feature).

    p8.png

  13. Double-click the WebTemplate.feature file (as you have the others), but do not set it as hidden. Instead, find the scope setting, and change it from Site to Farm as shown in the following screenshot.

    p4.png

    In the Properties window, find the Feature Id property and copy the GUID value (be sure to get all of it) and paste it into a Notepad document. You will need this later.
  14. Click the File menu, and choose Save All.
  15. In the Visual Studio Solution Explorer, right-click the project, and choose Package.

    p5.png
  16. Right-click again on the project, and choose Open Folder in Windows Explorer. In Explorer, navigate into the bin\Debug folder. Copy the TemplateDemo.wsp file from this folder to a location that has a shorter path, such as c:\Demo\ TemplateDemo .wsp.
  17. Close Visual Studio and open the SharePoint 2010 Management Shell from the Start Menu.
  18. Type in the following command to add your new solution to the farm:

    Add-SPSolution c:\Demo\ TemplateDemo.wsp
  19. Type in the following command to deploy your new solution globally in the farm:

    Install-SPSolution TemplateDemo.wsp -GACDeployment
  20. Close the SharePoint 2010 Management Shell, and open your Central Administration site in a browser.
  21. Click Create Site Collections under the Application Management group. In the Template Selection area, click the Custom tab, and notice that DemoTemplate now displays as a choice. You have now successfully made your web template available for global use! Use PowerShell to Deploy a Hierarchy of Sites.

Our last task is to create a hierarchy of sites using the template we modified in step 2 and create a PowerShell script that we develop. The following is the site taxonomy that we need to produce:

p6.png

Normally, you would create this type of hierarchy at the root (/) of a Web application, but simply use the managed path/sites for convenience in your development environment.

  1. Open a new instance of Notepad. Create a PowerShell script in this simple editor for this portion of the lab. Also, find the Feature Id GUID that you saved earlier in a Notepad document, and copy it to your Clipboard.
  2. Add the following lines at the top of the script to set some variables and values to reuse throughout the script: 

    $scUrl = "Url of the site"  
    $scOwner = "domain\userID"

    $template = "{pasteFeatureIdGUID}#DemoTemplate"

    Paste the Template Id GUID from your Clipboard over pasteFeatureIdGUID (retain the { } brackets). Also replace the domain\userID with the account that you use (that is a farm admin).
  3. Add the following line to create a new site collection and provision its rootweb:

    New-SPSite -Url $scUrl -OwnerAlias $scOwner-template $template -name "Home/News"

  4. Next, provision the Executives site with the next line:

    New-SPWeb ($scUrl + "/Executives") -template $template -name "Executives" | ft -p url  

    The| ft -p url simply formats the output that you see when you run the script.
  5. Continuing adding lines for all the sites listed in the desired site taxonomy. You need to copy and paste only the preceding line and change the two places where Executives displays, making sure that in the first instance you add the entire hierarchical path to the site. After you complete your script, save it into the c:\Demo folder, and call it ProvisionSites.ps1
  6. Open the SharePoint 2010 Management Shell.
  7. Type in the following line to execute your provisioning script:
       
    c:\lab2\ProvisionSites.ps1

  8. When your script completes without errors, open a web browser to  the url we given earlier.
  9. In addition to verifying that all the sites in the hierarchy have been created, you should also test to see that all the customizations you made to your template (versioning settings in the Shared Documents library) and initial content (the files you uploaded) are present.

Up Next
    Ebook Download
    View all
    Learn
    View all