Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
How to: Deploy a Document Template in a Sandboxed Solution

How to: Deploy a Document Template in a Sandboxed Solution

Overview

In previous versions of Microsoft® SharePoint®, resources such as document templates, application pages, and JavaScript files were deployed to the SharePoint root on the server file system, typically within the _layouts virtual directory. In SharePoint 2010, you cannot deploy any resources to the server file system from a sandboxed solution. Instead, your deployment must target the content database. This how-to topic describes how to manage the deployment of files and documents in a sandboxed solution.

For a practical example of the deployment of files and documents to the sandbox environment, see the Sandbox Proxy Reference Implementation.

Summary of Steps

This how-to topic includes the following steps:

  • Step 1: Create and Configure a Module. In this step, you create a feature manifest file that contains a Module element. This specifies which files to deploy and where to deploy them.
  • Step 2: Add the Module to a Feature. In this step, you create a feature and add your feature manifest file to the feature. This enables you to deploy the module to the SharePoint environment.
Ff798392.note(en-us,PandP.10).gifNote:
This how-to topic assumes that you have used the Microsoft Visual Studio® 2010 development system and one of the SharePoint 2010 templates to create a project.

Step 1: Create and Configure a Module

This procedure creates a feature manifest that contains a Module element. The module is configured to add files to the content database, which enables you to deploy it within a sandboxed solution.

To create a Module element

  1. In Solution Explorer, right-click the project node, point to Add, and then click New Item.
  2. In the Add New Item dialog box, in the Installed Templates pane, expand SharePoint, and then click 2010.
  3. Click Module, type a name for the module in the Name text box, and then click Add. This example uses the name Templates for the module.

    Ff798392.89561eb0-c7ab-444d-8b22-3d8d4b11345f(en-us,PandP.10).png

    In Solution Explorer, notice that Visual Studio has added a Templates node to represent your module.

    Ff798392.b0f7ad71-e06b-4b34-ae83-8dbf2a3986e0(en-us,PandP.10).png

  4. Expand the Templates node, and then open the feature manifest file (Elements.xml). By default, the feature manifest includes a Module element with a placeholder File child element, as shown in the following XML.
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Module Name="Templates">    <File Path="Templates\Sample.txt" Url="Templates/Sample.txt" />
      </Module>
    </Elements>
    
    
  5. In the Elements.xml file, delete the placeholder File element. You can also delete the Sample.txt file from Solution Explorer.
  6. In Solution Explorer, right-click the Templates node, point to Add, and then click Existing Item.
  7. Browse to the file or files you want to deploy, and then click Add.
  8. Notice that Visual Studio adds a File element for each file that you add, as shown in the following XML. This example adds an Excel template named Estimate.xltx.
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Module Name="Templates">    <File Path="Templates\estimate.xltx" Url="Templates/estimate.xltx" />    
      </Module>
    </Elements>
    
    
  9. In the Module element, add a Url attribute to specify the destination for the files. In this example, a document template for a content type is being deployed, so a value of _cts/Estimate is specified.
    Ff798392.note(en-us,PandP.10).gifNote:
    In SharePoint 2010, like in earlier versions of SharePoint, content types and document templates are stored as subfolders in the _cts virtual directory.

  10. Make the following changes to the File element:
    1. Leave the Path attribute value as Templates\estimate.xltx. This tells the feature where to find the file in your Visual Studio project.
    2. Change the Url attribute value to estimate.xltx. This specifies the virtual path to the file, within the virtual directory specified by the Module element.
    3. Add a Type="Ghostable" attribute value. This indicates that the file will be stored in the content database.
    Ff798392.note(en-us,PandP.10).gifNote:
    Visual Studio 2010 does not always automatically pick up the feature manifest schema. If you see schema errors or you lack IntelliSense support when you edit a feature manifest, check the properties of the XML document in the Properties window. The Schemas property should be set to 14\TEMPLATE\XML\wss.xsd.

  11. The feature manifest should resemble the following.
     <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Module Name="Templates" Url="_cts/Estimate">    <File Path="Templates\estimate.xltx" 
              Url="estimate.xltx" 
              Type="Ghostable" />    
      </Module>
    </Elements>
    
    
    Ff798392.note(en-us,PandP.10).gifNote:
    For sandboxed deployments, you can use Type attribute values of Ghostable or GhostableInLibrary. Use GhostableInLibrary if your deployment target is a document library and you want SharePoint to create a parent list item for your file.

Step 2: Add the Module to a Feature

This procedure adds the module to a feature, which provides the mechanism to deploy your files to the SharePoint environment.

To add a module to a feature

  1. In Solution Explorer, right-click the Features node, and then click Add Feature.
    Ff798392.note(en-us,PandP.10).gifNote:
    Visual Studio 2010 may have already added an empty feature when you added other SharePoint components. In this case, you can either rename the empty feature or delete it and create a new one.

  2. In Solution Explorer, right-click the new feature node, and then click Rename. This example uses the name TemplatesFeature for the feature.
  3. If the Feature Designer is not already open, double-click the TemplatesFeature node to open the designer.
  4. In the Feature Designer, select an appropriate scope. You can use a feature scope value of Web or Site within a sandboxed solution.
  5. In the Items in the Solution pane, click the Templates module.
  6. Click the right arrow button to add the module to the feature. This moves the Templates module to the Items in the Feature pane.

    Ff798392.b57dec78-8f2f-4ff7-957c-7a3f5ee8e420(en-us,PandP.10).png

  7. To deploy the feature, right-click the project node in Solution Explorer, and then click Deploy.
    Ff798392.note(en-us,PandP.10).gifNote:
    This example deploys the document template to the _cts virtual directory. This location is not directly accessible to end users. You can use steps 8–11 to verify that the file was deployed successfully.

  8. Open your site in SharePoint Designer.
  9. In the Site Objects pane, click All Files.
  10. In the main window, click _cts.
  11. Click the Estimate folder, and verify that the folder contains the file Estimate.xltx.

For more information about provisioning files into SharePoint sites, see How to: Provision a File and How to: Include Files by Using a Module on MSDN.


Show:
© 2015 Microsoft