This is the second installment in a four-part series about the time-off request solution, an end-to-end Microsoft Office SharePoint Server 2007 solution that uses Microsoft Office Word 2007 as a form application. In the previous post I created the site columns for the solution and included them in a site content type. This post focuses on the Office Word 2007 document template and the binding of content controls to those site columns.

The initial Office Word 2007 document template for this solution is relatively straightforward. There are three layout tables used to identify the employee and employee’s manager, information about the time-off request, and the status of the request. As can be seen in the following figure, placement of the content controls will be obvious.

Initial Word Template

Before adding the content controls, you must first add the document template to the existing Time-Off Request site content type. To add the document template:

  1. Navigate to the Site Settings page for the site collection (in this case, the Human Resources site collection).
  2. In the Galleries section, click Site content types.
  3. In the Custom Content Types section, click Time-Off Request.
  4. On the Site Content Type page, click Advanced settings.
  5. On the Site Content Type Advanced Settings page, click Upload a new document template.
  6. Click Browse and use the Choose file dialog box to add the initial Office Word 2007 document template.
  7. On the Site Content Type Advanced Settings page, click OK.

By default, when you update a document template for a site content type, all child sites and lists inheriting from the site content type are updated as well. For our solution, this means that the Time-Off Request and Time-Off Request Status document libraries will be updated to use the new document template. When I navigate to either document library and click New | Time-Off Request, I can see my initial document template.

When Office Word 2007 starts, note the document information panel that appears at the top. The default document information panel, a Microsoft Office InfoPath 2007 form, exposes all of the site columns in our content type. For this solution, the employee and employee’s manager will use the document information panel to update corresponding content controls, which are also mapped to the site columns. In Part 3 I will take a closer look at the document information panel and show how InfoPath declarative rules can drive most of the business logic of the time-off request form. For now, however, I will just add the content controls to our document template, starting with the one for the employee name:

  1. Place the cursor in the empty cell next to the Name heading, below Employee Information.
  2. Click the Insert tab.
  3. In the Text group, click Quick Parts | Document Property and note the site columns that are available as content controls.
  4. Click EmployeeName to add that content control to the document template.
    EmployeeName Content Control
  5. Repeat the previous four steps for all of the other empty cells in the document template, substituting the correct site column for EmployeeName.

When you are done adding all of the content controls, the document template should appear as shown below. Note that the TimeOffStart and TimeOffReturn site columns, which were defined as “Date and Time” data types, are mapped to date picker content controls. Also, the TimeOffType and TimeOffStatus site columns, which were defined as “choice” data types, are mapped to drop-down list content controls.

Updated Word Template

I mentioned earlier that the employee and employee’s manager will use the document information panel to update data in the form. This will give our solution free business logic that is available with the Office InfoPath 2007 declarative rules engine. It also means that we can lock all of the content controls, preventing users from making edits directly in the document template. To modify the properties of a content control, you will need to enable the Developer tab in the ribbon. Following are the steps needed to lock down a content control:

  1. Click the Office button (File menu) and click Word Options.
  2. In the Word Options dialog box, in the Popular tab, select the Show Developer tab in the Ribbon check box and click OK.
  3. Select the EmployeeName content control in the document template and click the Developer tab.
  4. In the Controls group, click Properties.
  5. In the Content Control Properties dialog box, select the Content control cannot be deleted and Contents cannot be edited check boxes.
    Locking a Content Control
  6. Click OK.
  7. Repeat the previous four steps for all content controls in the document template.

If you are interested in adding a default file-naming convention for the document template, you can do so using content controls. With the current version of the document template, when a user clicks Save, the default file name is Litware.docx. That is because Office Word 2007 will grab the first line of text in the document, stopping when it encounters a character that is not a space or alphanumeric (e.g., comma, dash, slash, etc.). To enforce a default file-naming convention for this template, I will replace the “Litware, Inc.” text at the top of the document with two side-by-side content controls: EmployeeName and TimeOffStart.

Enforcing a File-Naming Convention

Again, I will lock down these two content controls to prevent deletion or direct edits in the document template. Additionally, for the TimeOffStart control, I will select a date format that contains only alphanumeric characters and spaces.

Date Format

With all of our content controls added and a default file-naming convention in place, the last step in making the template act like a form is to prevent users from making changes to any of the document headings. Office Word 2007 includes a grouping feature that can lock any content in a document. To group the entire template and prevent users from making any changes directly in the document:

  1. Press CTRL+A to select the entire document.
  2. Click the Developer tab.
  3. In the Controls group, click Group | Group.

The document template is now ready to be added back to the Time-Off Request site content type. Click the Save icon on the toolbar, change the name to something like TimeOffRequest.docx, and save the file to your local drive (not the document library from where you started the document template). Then, close Office Word 2007 and perform the following to update the Time-Off Request site content type:

  1. Navigate to the Site Settings page for the site collection (in this case, the Human Resources site collection).
  2. In the Galleries section, click Site content types.
  3. In the Custom Content Types section, click Time-Off Request.
  4. On the Site Content Type page, click Advanced settings.
  5. On the Site Content Type Advanced Settings page, click Upload a new document template.
  6. Click Browse and use the Choose file dialog box to add the Office Word 2007 document template you just saved to the local drive.
  7. On the Site Content Type Advanced Settings page, click OK.

Now, when you navigate to either the Time-Off Request or Time-Off Request Status document library and click New | Time-Off Request, the updated template will start in Office Word 2007. With the new template, the only way to modify the time-off request form is through the document information panel. In the next post about this solution, I will add business logic to the document information panel that simplifies data entry for the employee and employee’s manager.