Modifying the Document Library s File Type Behaviors


Modifying the Document Library's File Type Behaviors

SharePoint 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 Icon

Document 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

<DocIcons> . . .   <ByExtension> . . .     <Mapping Key="one" Value="icone.gif"              EditText="Microsoft Office OneNote"              OpenControl="SharePoint.OpenDocuments"/>     <Mapping Key="pdf" Value="pdf.gif" />     <Mapping Key="png" Value="icpng.gif"/>     <Mapping Key="pot" Value="icpot.gif"              EditText="Microsoft Office PowerPoint"              OpenControl="SharePoint.OpenDocuments"/>     <Mapping Key="ppt" Value="icppt.gif"              EditText="Microsoft Office PowerPoint"              OpenControl="SharePoint.OpenDocuments"/>. . . . 

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 Icons

DOCICON.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.

Table 5.2. <Mapping> Attributes

Attribute

Required

Type

Description

AcceptHeader

No

Text

Specifies the client application to use to open this document type. If the specified client application does not exist on the user's computer, SharePoint can render the contents of the document as HTML. See the Microsoft.HtmlTrans.Interface namespace for more information.

EditText

No

Text

Specifies a friendly name for the application that will edit the document.

HandlerUrl

No

Text

Specifies a server URL that will convert the document's content to HTML when the user does not have the specified client application installed.

Key

Yes

Text

Specifies the file extension if in the ByExtension section or the ProgID if in the ByProgID section.

OpenControl

No

Text

Specifies the ActiveX control to use to open the document for editing.

Value

No

Text

Specifies the icon's filename. The icon must exist within the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\Template\Images folder or sub-tree.


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

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=windows-1252"> <meta name=ProgId content=Word.Document> . . . 

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

<DocIcons>   <ByProgID>     <Mapping Key="Excel.Sheet" Value="ichtmxls.gif"              EditText="Microsoft Office Excel"              OpenControl="SharePoint.OpenDocuments"/>     <Mapping Key="FrontPage.Editor.Document" Value="ichtmfp.gif"              EditText="Microsoft Office FrontPage"              OpenControl="SharePoint.OpenDocuments"/>     <Mapping Key="PowerPoint.Slide" Value="ichtmppt.gif"              EditText="Microsoft Office PowerPoint"              OpenControl="SharePoint.OpenDocuments"/>     <Mapping Key="Publisher.Document" Value="ichtmpub.gif"              EditText="Microsoft Office Publisher"              OpenControl="SharePoint.OpenDocuments"/>     <Mapping Key="SharePoint.WebPartPage.Document"              Value="icsmrtpg.gif"              EditText="Microsoft Office FrontPage"              OpenControl="SharePoint.OpenDocuments"/>     <Mapping Key="Word.Document" Value="ichtmdoc.gif"              EditText="Microsoft Office Word"              OpenControl="SharePoint.OpenDocuments"/>     <Mapping Key="XDocs.Document" Value="icxddoc.gif"              EditText="Microsoft Office InfoPath"              OpenControl="SharePoint.OpenXMLDocuments"/>     <Mapping Key="InfoPath.Document" Value="icxddoc.gif"              EditText="Microsoft Office InfoPath"              OpenControl="SharePoint.OpenXMLDocuments"/>   </ByProgID>   <ByExtension>     <Mapping Key="asax" Value="icasax.gif"/>     <Mapping Key="ascx" Value="icascx.gif"/>     <Mapping Key="asmx" Value="icasmx.gif"/>     <Mapping Key="asp" Value="icasp.gif"/>     <Mapping Key="aspx" Value="icaspx.gif"/>     <Mapping Key="bmp" Value="icbmp.gif"/>     <Mapping Key="cat" Value="iccat.gif"/>     <Mapping Key="chm" Value="icchm.gif"/>     <Mapping Key="config" Value="icconfig.gif"/>     <Mapping Key="css" Value="iccss.gif"/>     <Mapping Key="db" Value="icdb.gif"/>     <Mapping Key="dib" Value="icdib.gif"/>     <Mapping Key="disc" Value="icdisc.gif"/>     <Mapping Key="doc" Value="icdoc.gif"              EditText="Microsoft Office Word"              OpenControl="SharePoint.OpenDocuments"/> . . . 

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.




SharePoint 2003 Advanced Concepts. Site Definitions, Custom Templates, and Global Customizations
SharePoint 2003 Advanced Concepts: Site Definitions, Custom Templates, and Global Customizations
ISBN: 0321336615
EAN: 2147483647
Year: 2006
Pages: 64

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net