Share via


How to: Add a Document Template, File Type, and Editing Application to a Site Definition

Applies to: SharePoint Foundation 2010

This programming task provides steps for customizing Microsoft SharePoint Foundation so that documents can be created or edited from a third-party application.

The task involves the following subtasks:

  • Creating a document template file, which in effect adds a DocumentTemplate element to the Onet.xml file of the site definition.

  • Adding a Mapping element to DocIcon.xml to specify a file type icon and identify the control to use when a user opens the file.

  • Creating a DLL that provides the similar functionality to what is described for the OpenDocuments control—that is, the ability to create, open, and edit documents of the file type.

To perform the customizations described in this topic, you must be an administrator on the server that is running SharePoint Foundation.

Warning

Changes that you make to originally installed files may be overwritten when you install updates or service packs for SharePoint Foundation, or when you upgrade an installation to the next product version.

Adding a Document Template

To add an application document as a template that can be used in document libraries, you can either specify the DocumentTemplate element within a Content Type Feature (see Deploying Content Types), or specify the DocumentTemplate element within the Onet.xml file of a custom site definition (see How to: Create a Custom Site Definition and Configuration).

The following example shows how to use the DocumentTemplate element in the Onet.xml file.

<DocumentTemplates>
   <DocumentTemplate DisplayName="Blank Document" Type="105" 
      Default="FALSE" Description="A blank document.">
      <DocumentTemplateFiles>
         <DocumentTemplateFile 
            Name="doctemp/Template_Folder/psdtmp1.psd" 
            TargetName="Forms/template.psd" Default="True"/>
      </DocumentTemplateFiles>
   </DocumentTemplate>
</DocumentTemplates>

The DisplayName attribute of the DocumentTemplate element specifies the text that is displayed in the drop-down list for selecting a document template type when you create a new document library. The Type attribute uniquely identifies the document type and can be any integer that is not already used for another document template. The Default attribute specifies whether the template is selected by default in the drop-down list. The Name attribute of the DocumentTemplateFile specifies the physical path to the template file on the server computer, and the TargetName attribute specifies the address of the template relative to the document library.

Reset Internet Information Services (IIS) for changes to take effect.

Adding a Mapping Definition for a File Type

To map a file name extension to a document type, and to identify the control to use when you open a document that has the file name extension, add a Mapping element to DocIcon.xml. DocIcon.xml is located in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\XML directory.

Adding the following line in the ByExtension element in DocIcon.xml maps the .psd extension to an image file named icpsd.gif, which provides the icon that is displayed in document libraries for files of this type:

<Mapping Key="psd" Value="icpsd.gif"/>

To enable editing within an application, the Mapping element must also include the EditText attribute and the OpenControl attribute, as follows:

<Mapping Key="psd" Value="icpsd.gif" EditText="Application" OpenControl="ProgID"/>

The EditText attribute specifies the application name that is displayed on the drop-down menu when a user clicks the Edit arrow for a document. The OpenControl attribute specifies the programmatic identifier (ProgID) of the control to use for opening files of the specified type.

The image file that is specified by the Value attribute must reside in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\IMAGES directory. If the specified image file is missing from this directory, a "missing image" icon appears beside the document.

To prevent users from being prompted for credentials to see the icon when Anonymous Access is enabled, you must set inheritable permissions on the image file.

To set inheritable permissions on the image file

  1. Right-click the referenced image file in the IMAGES folder, and then click Properties.

  2. In the Properties dialog box, on the Security tab, click Advanced.

  3. In the Advanced Security Settings dialog box, on the Permissions tab, ensure that the check box is selected for Allow inheritable permissions from the parent to propagate to this object and all child objects. Include these with entries specifically defined here.

Note

The default size for icons in SharePoint Foundation is 16 x 16 pixels.

Reset IIS for changes to take effect.

Adding an Editing Application

Create a DLL that provides the control to load for a document of the specified type whose ProgID identifies the control, for example, SharePoint.OpenDocuments. The control that you create must provide the same methods for creating, opening, and viewing documents as described for the OpenDocuments control.

See Also

Concepts

Understanding Onet.xml Files

Understanding DocIcon.xml Files