Microsoft KB Archive/917662

= How to make sure that Word 2007 documents that are created in a Windows SharePoint Services 3.0 document library use an up-to-date version of the document template =

Article ID: 917662

Article Last Modified on 10/15/2007

-

APPLIES TO


 * Microsoft Office Word 2007, when used with:
 * Microsoft Windows SharePoint Services 3.0

-



INTRODUCTION
This article discusses how to make sure that Microsoft Office Word 2007 documents that are created in a Microsoft Windows SharePoint Services 3.0 document library use an up-to-date version of the document template.

When a user opens a document template that is located in a Windows SharePoint Services 3.0 document library, Word 2007 downloads a copy of the document template to the Temporary Internet Files folder on the user's computer. When a user closes the document template, Word 2007 deletes the copy of the document template on the user's computer.

However, when a user opens a document in the Windows SharePoint Services 3.0 document library that is based on the document template, the document still uses the document template that was downloaded to the user's computer. Therefore, if the document template changes, documents that are based on the document template are not updated to use the latest version of the document template.

To make sure that a document uses an up-to-date version of a document template, associate the document template with an XML expansion pack manifest file. Then, add code to the document template to link documents that are based on the document template to the copy of the document template that is downloaded to the user's computer.



MORE INFORMATION
To make sure that a document uses an up-to-date version of a document template, follow these steps:
 * 1) Create an XML expansion pack. Associate the XML expansion pack manifest file with the document template. The XML expansion pack downloads a copy of the document template to the user's computer. The XML expansion pack also updates the copy of the document template on the user's computer, if it is required.
 * 2) Add Microsoft Visual Basic for Applications (VBA) code to the document template. The code links documents that are based on the document template to the copy of the document template that is downloaded to the user's computer.

To do this, follow these steps.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.  Start Word 2007. Create a document template. Then, save the document template in the Forms folder of the Windows SharePoint Services 3.0 document library.

Note Make sure that the document template uses either the .dot file name extension or the .dotm file name extension. Create an XML expansion pack. To do this, follow these steps:   In Word 2007, create an XML schema file that does not contain any content. Then, save the XML schema file in the Forms folder of the Windows SharePoint Services 3.0 document library. The following is an example of an XML schema file that does not contain any content.  &quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;>   In Word 2007, create an XML expansion pack manifest file. Then, save the XML schema file in the Forms folder of the Windows SharePoint Services 3.0 document library. The following is an example of an XML expansion pack manifest file.  1.0            <-- XML Schema file targetNamespace above --> <solutionID>testSolution</solutionID> other <alias lcid=&quot;*&quot;>Template template 1.0                        <filePath><-- template file name --></filePath> <templateID><-- {GUID} --></templateID> <solutionID>testSolution-Schema</solutionID> schema <alias lcid=&quot;*&quot;>Template schema 1.0                        <filePath><-- XML Schema file name --></filePath> </li></ol>

Note The XML expansion pack manifest file must be signed with a digital certificate. For information about how to sign the XML expansion pack manifest file with a digital certificate, see the Microsoft Office 2003 Smart Document Software Development Kit (SDK). To obtain the Smart Document SDK, visit the following Microsoft Web site:

http://www.microsoft.com/downloads/details.aspx?familyid=24A557F7-EB06-4A2C-8F6C-2767B174126F&displaylang=en

</li>  Add the following VBA code to the document template that you created in step 2. Private Sub Document_New 'temporarily unlink this file from the template ActiveDocument.AttachedTemplate = &quot;&quot; 'and update UpdateTemplate End Sub

Sub UpdateTemplate 'if the user does not download the XEP at least once, this will fail - so we'll just continue along silently On Error Resume Next

Dim strTemplatePath As String 'get file name for local template - to do this, we need this path: %USERPROFILE%\Local Settings\Application Data\Microsoft\Schemas\ \<solutionID>\ strTemplatePath = Environ(&quot;USERPROFILE&quot;) + &quot;\Local Settings\Application Data\Microsoft\Schemas\&quot; + &quot;<-- namespace with _ for illegal chars -->&quot; + &quot;\&quot; + &quot;<-- solution ID for template --> &quot; + &quot;\&quot; + &quot;<-- template file name -->&quot; 'relink us to local template ActiveDocument.AttachedTemplate = strTemplatePath End Sub

Private Sub Document_Open 'do not do anything in the case where the solution author opens the template directly If (InStr(1, ActiveDocument.FullName, &quot;.dotm&quot;, vbTextCompare) = 0) Then 'temporarily unlink this file from the template ActiveDocument.AttachedTemplate = &quot;&quot; 'update template UpdateTemplate End If       End Sub Note The document template must be signed with a digital certificate. For more information about how to sign a document template with a digital certificate, see Word 2007 Help. </li> Link the document template to the Windows SharePoint Services 3.0 document library. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> Connect to the Windows SharePoint Services 3.0 document library, click Settings, and then click Document Library Settings.</li> On the Customize  page, click Advanced settings under General Settings.</li> On the Document Library Advanced Settings:  page, type the URL of the document template in the Template URL box, and then click OK.</li></ol> </li></ol>

<div class="references_section">