Modifying the Document Library's File Type BehaviorsSharePoint can display an icon for each document in the library. This document icon is based on that document's file extension. Icons provide a quick way for users to scan the document library to zero in on the file for which they are searching. Figure 5.10 shows a document library with several different file types and their associated icons. Figure 5.10. Shared Documents without PDF icon.One noticeably incorrect icon in Figure 5.10 is the PDF icon. In actuality, this isn't a SharePoint error. SharePoint simply does not define an icon for Adobe or any other vendor's file types. When an undefined file type is encountered, SharePoint displays its default icon (ICGEN.GIF). As with everything else in SharePoint, document icons can be customized. We can therefore configure SharePoint to display the PDF icon for PDF documents or any other file extension rather easily. Adding a PDF IconDocument type mappings to document icons are defined within DOCICON.XML, which is found in C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\XML. Mapping a document icon to a file extension is as simple as adding a single line to the XML file. As shown in Listing 5.6, we added an additional Mapping element to DOCICON.XML so that it would show a PDF icon for a PDF document. Listing 5.6. DOCICON.XML Extension
Mapping's Key attribute specifies the file extension, while the Value attribute specifies the icon to display. Because the image is retrieved from the _layouts/images virtual folder, our PDF icon must be copied to the C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\IMAGES folder. PDF.GIF is deployed with Adobe Acrobat Professional. Assuming you have installed Acrobat Professional on your computer, you should find the image in one of the folders under C:\Program Files\Adobe. Alternatively, there are several resources on the Internet where you can download the PDF.GIF icon. After performing an IISReset, the PDF icon will appear next to PDF documents in the document library. This is shown in Figure 5.11. Figure 5.11. Shared Documents with PDF icon.DOCICON.XML: Beyond File Extensions and IconsDOCICON.XML defines more than the mapping of an icon to an extension. It also associates a file's meta name to an icon and defines how to open, edit, and render files. This rich functionality is summarized in Table 5.2.
In the previous section, we discussed how to associate an icon with an extension. However, SharePoint provides an additional way to associate icons with files. This additional way is through examination of a file's meta tags. Listing 5.7 details the top portion of a Microsoft Office document saved as an HTML file. As you can see, there is quite a bit of embedded information that tells us that this file was authored by Microsoft Word. The most official of these hints is the bolded meta tag that has a name attribute of ProgID. SharePoint uses the content attribute of this tag to associate an icon with the file. The icon determined from the meta tag takes precedence over an icon determined from the document extension. Listing 5.7. MyFile.HTM with a meta Tag Linking It to Microsoft Word
From Listing 5.8, you can see that a file's behaviors (icons, opening, editing, and rendering) are defined through its meta tag or extension. The bolded elements in the listing define a Word document's behaviors for both meta tag and extension. Listing 5.8. DOCICON.XML ProgID and Extension
When associating a file's meta tag with an icon, SharePoint matches the file's content attribute with the DOCICON.XML's Key attribute. Because our example has a content attribute valued as Word.Document, the icon with a Key of Word.Document will be selected. This is shown in Figure 5.12 with the file Word Saved As HTM. Notice that the ICHTMDOC.GIF icon is displayed instead of the icon associated with HTM files. As stated previously, an icon determined from the meta tag takes precedence over an icon determined from the document extension. Figure 5.12. Shared Documents with meta tag associated icons.One of the features afforded to Microsoft Office documents is that they have an Edit in Microsoft Office FrontPage/Excel/PowerPoint/Word selection from the drop-down menu. This feature, shown in Figure 5.13, is customized from DOCICON.XML. Figure 5.13. Document library drop-down menu.
The Mapping element's EditText helps to specify the text to display in the menu. In Listing 5.8, we see that the text is Microsoft Office Word. As shown in Figure 5.13, SharePoint prepends "Edit in" to that text. It therefore displays "Edit in Microsoft Office Word" in the menu. More extensive changes, such as those explained in Chapter 2, "Site Definitions," and shown in Figure 2.6, can be accomplished through JavaScript manipulation. We further see in Listing 5.8 that the OpenControl specifies a value of SharePoint.OpenDocuments. This value references a Microsoft ActiveX control that is used to open the document. SharePoint.OpenDocuments is authored by Microsoft and can only open Microsoft Office documents. It cannot open Acrobat (PDF) or other types of documents. You could build your own ActiveX control to extend the functionality of SharePoint.OpenDocuments. It could provide more integration with SharePoint and non-Office applications. The supporting SharePoint web pages would need to be edited to support this upgraded ActiveX control and facilitate its download to the user's computer. Furthermore, client applications integrated with this ActiveX control would need to support WebDAV for them to save their edits. Another alternative is to use the site definition's CustomJSUrl directly. JavaScript could enable the direct modification of the menu and the creation of a simpler implementation that did not need to duplicate all the SharePoint.OpenDocuments methods. |