How to: Add a Document Template, File Type, and Editing Application to a Site Definition
Published: May 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 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.
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.
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).
<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.
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:
To enable editing within an application, the Mapping element must also include the EditText attribute and the OpenControl attribute, as follows:
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
Right-click the referenced image file in the IMAGES folder, and then click Properties.
In the Properties dialog box, on the Security tab, click Advanced.
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.
The default size for icons in SharePoint Foundation is 16 x 16 pixels.
Reset IIS for changes to take effect.
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.