Compartilhar via


Adding a Document Template, File Type, and Editing Application to a Site Definition

This programming task provides steps for customizing Microsoft® Windows® SharePoint™ Services so that documents can be created or edited from a third-party application. The task involves creating a document template file to complement the ONET.XML file of the site definition, modifying the DOCICON.XML file, and creating a DLL that provides the same functionality as described for the OpenDocuments control.

Adding the ability to create or edit documents within an application 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 for a file type icon and for identification of the control to use to open the file.
  • Creating a DLL that provides the necessary functions for creating or editing documents in the application.

Note  To perform the customizations described in this topic, you must be an administrator on the front-end server running Windows SharePoint Services.

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

Adding a document template

To add an existing application document as a template that can be used in document libraries, create an XML file in the Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\Locale_ID\Site_Definition\XML folder containing the ONET.XML file. Give the new file a name in the format doctemp*.xml, where * represents arbitrary text used as part of the file name. Windows SharePoint Services searches this directory for any .xml file that begins with "doctemp" and merges its contents with the document template definitions contained in ONET.XML. The advantage to adding a doctemp*.file, as opposed to modifying ONET.XML directly, is that the custom definition will not be overwritten when Windows SharePoint Services is updated.

The following example shows the format of a doctemp*.xml file for adding a document template. The file can be created in Notepad and given any name that begins with doctemp, for example, doctempmyTemplate.xml.

<?xml version="1.0" encoding="utf-8" ?>
<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 creating 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 element specifies the physical path to the template file on the server computer, while the TargetName attribute specifies the address of the template relative to the document library.

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

Adding a mapping definition for a file type

To map a file extension to a document type, and to identify the control to use when opening a document that has the file extension, add a Mapping element to DOCICON.XML. DOCICON.XML resides in the Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\XML directory.

Adding the following line within 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 EditText and OpenControl attributes, 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 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 Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\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 by performing the following steps:

  • Right-click the referenced image file in the IMAGES folder, and then click Properties.
  • On the Security tab in the Properties dialog box, click Advanced.
  • On the Permissions tab in the Advanced Security Settings dialog box, 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 Windows SharePoint Services is 16 x 16 pixels.

Reset IIS for changes to take effect.

Adding an editing application

Create a DLL providing 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.