The Outlook View Control


Outlook 2000 included an add-on product named the Outlook View control. With Outlook 2002 and later, the Outlook View control ships as a core part of Outlook, so it is not necessary to download any separate controls to get it. The Outlook View control is an ActiveX wrapper around Outlook views such as Table, Calendar, Card, and Timeline. You can use this ActiveX control within a Web application, such as an Active Server Pages (ASP) application, or within your folder home page. This control saves you from having to rewrite significant portions of code to mimic Outlook functionality. Figure 8-15 shows the second folder home page example (FullContacts.htm), which hosts the View control.

click to expand
Figure 8-15: A folder home page (FullContacts.htm) that hosts the Outlook View control

The environment in which you place the View control determines the control's functionality. For example, when you place the View control in a folder home page, the control provides full access to the Outlook object model as well as automatic merging of menu commands with the Outlook container, as shown in Figure 8-16. In contrast, within a standalone Web page, the control does not allow access to any user data, nor does it provide access to the entire Outlook object model. This restriction prevents the control from downloading all the Outlook data when a user accesses the Web page. In either scenario, the View control does require Outlook to be installed on the machine. The control does not install Outlook for you.

click to expand
Figure 8-16: When hosted in a folder home page, the View control automatically merges menu commands with its Outlook container.

The View control allows you to programmatically change control properties so that you can place more than one control on a single page in your application. For example, you might want to show a side-by-side view of two calendars, or maybe a contacts list and all tasks associated with the currently selected contact. When multiple View controls are on a single page, the control with the focus determines the menu items available to the user.

Setting Up the Second Folder Home Page

Using a machine that has Outlook with Visual Basic Scripting Support and Collaboration Data Objects components installed, follow these steps to set up the second folder home page, which uses the Outlook View control:

  1. In Outlook, right-click on the Account Tracking folder and choose Properties.

  2. In the Address text box of the Home Page tab, specify the location of the FullContacts.htm file ”for example, file://C:\Webview\FullContacts.htm ”and click OK. (FullContacts.htm is included with the book's sample files.)

  3. Click on the Account Tracking folder to display the folder home page.

The following section outlines how to add the View control to a Web page and program it.

Using the Outlook View Control

Adding a View control to your folder home page or Web page is actually quite easy. All you do is add the OBJECT tag to your page and give the control an ID that you will use in your program. For the Account Tracking folder home page, this OBJECT tag is inserted into the HTML page:

 <OBJECT ID="oViewControl" WIDTH=100% HEIGHT=84% style="border-bottom:1px silver solid" CLASSID="CLSID:0006F063-0000-0000-C000-000000000046">    <param NAME="Namespace" VALUE="MAPI">    <param NAME="Folder" VALUE="">    <param NAME="View" VALUE="Accounts"> </OBJECT> 

This tag creates the View control object. Also notice the param tags ”you can use these tags to pass parameters to the control. This example passes in MAPI for the Namespace parameter. It also passes in the folder, using a blank value so the control defaults to the folder that the user is currently looking at. Finally, it passes in, as a string, the default view we want in the control. The Accounts view is the default view for the Account Tracking folder.

After you insert the control, you can add code to the folder home page to grab the Outlook Application object, Window.External.OutlookApplication , using the technique you saw earlier. Because this script must be running in the Account Tracking folder (because this is the folder home page for that folder), I set a variable to the current folder so that I can use that variable later in the script.

After the folder variable is set, the code needs to accomplish one more task. Recall that the View control will bring up the default folder that the user is viewing. However, this folder might not be the Account Tracking folder. To ensure that the control displays the Account Tracking folder, the code finds the full path to the Account Tracking folder and passes this path as one of the control's properties, Folder . (For example, if the Account Tracking folder is a top-level folder in the Favorites folders, the path will be \\Public Folders\Favorites\Account Tracking\.) The code then fills in the total number of accounts, contacts, and tasks in the folder. The code for this process is shown here:

 <SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>      '****************************************************** 'In-line code ' 'These lines of code are run when the browser reaches 'them while parsing the document. They set up the global 'variables that are needed throughout the application. '******************************************************      Set oApplication = window.external.OutlookApplication Set oNS = oApplication.GetNamespace("MAPI") Set oCurrentFolder = oApplication.activeExplorer.currentfolder Set oAccountFolder = oCurrentFolder 'AvailWidth = document.body.clientWidth      '****************************************************** 'Function StrFullPath ' 'This function creates and returns the full path to the 'folder '****************************************************** Function StrFullPath()    If oCurrentFolder Is Nothing Then       strFolderName = ""    End If    Set olCollabFolder = oCurrentFolder    strFolderName = ""    Set olRoot = oCurrentFolder    While (olRoot <> "Mapi")       strFolderName = oCurrentFolder.Name & "\" & strFolderName       Set olRoot = oCurrentFolder.Parent       If olRoot <> "Mapi" Then          Set oCurrentFolder = oCurrentFolder.Parent       End If    Wend    strFullPath = "\" & strFolderName End Function      '****************************************************** 'Sub FillTotals() ' 'This subroutine gets the count for the different types 'of items in a folder, such as accounts, contacts, and 'tasks. It also fills in the HTML page with this 'information.  '****************************************************** Sub FillTotals()    RestrictString = ""    RestrictString = "[Message Class] = ""IPM.Post.Account info"""    Set oAccounts = oAccountFolder.Items.Restrict(RestrictString)    oAcctCount = oAccounts.Count    AccountTotal.innerHTML = "<STRONG>" & oAcctCount & "</STRONG>"    RestrictString = ""    RestrictString = _       "[Message Class] = ""IPM.Contact.Account contact"""    Set oContacts = oAccountFolder.Items.Restrict(RestrictString)    oContactCount = oContacts.Count    ContactTotal.innerHTML = "<STRONG>" & oContactCount & "</STRONG>"    RestrictString = ""    RestrictString = "[Message Class] = ""IPM.Task"""    Set oTasks = oAccountFolder.Items.Restrict(RestrictString)    oTasksCount = oTasks.Count    TaskTotal.innerHTML = "<STRONG>" & oTasksCount & "</STRONG>" End Sub      Fullpath = StrFullPath() oViewControl.Folder = FullPath      '****************************************************** 'Sub Window_onLoad() ' 'This subroutine is called when the HTML page is loaded '****************************************************** Sub Window_onLoad()    oViewControl.Folder = Fullpath    'oViewControl.width = AvailWidth    txtFolder.innerHTml = oAccountFolder.Name    FillTotals() End Sub 

Now that some of the information for the HTML page is filled in, we need to add some buttons to the page to enable the user to call our subroutines that automate the View control. I've left out the HTML code that creates the buttons (you can look at this code in the FullContacts.htm file), but we will examine the automation code that drives the View control from these buttons.

The application provides six buttons and a drop-down list for changing the View control. The drop-down list enables the user to change the view of the control to one of the other views in the Outlook folder. Figure 8-17 shows another view of the Account Tracking folder home page.

click to expand
Figure 8-17: The folder home page for the Account Tracking application, which contains the Outlook View control

The View control has no methods for creating new views, so the views must be predefined for the folder. To change the view by using code, you set the View property on the control to the name of the view you want. Because a fully functional Outlook application is running in the control, users can right-click on view columns to bring up the Field Chooser or customize the view directly in the page. The following code implements changing the views of the control:

 '****************************************************** 'Sub WhatView_onChange ' 'This subroutine changes the view of the Outlook control 'depending on what the user picked in the drop-down list '****************************************************** Sub WhatView_onChange    oViewControl.View = WhatView.Value    window.Focus End Sub 

Implementing the functionality for the buttons is also pretty straightforward. Using the buttons, the user can create new accounts, expand groups, collapse groups, add a folder to a favorites list, find an item in a folder, and view the address book. Most of these actions are already contained in the View control as methods. For example, to view the address book, all the code has to do is call the AddressBook method on the View control. The same applies to adding the folder to the favorites ”all the code has to do is call the AddtoFavorites method on the View control. Here's the code for the buttons:

 '****************************************************** 'Sub CreateAccount ' 'This subroutine creates a new account info form and 'displays it for the user to fill in '****************************************************** Sub CreateAccount()    Set oAccount = oAccountFolder.Items.Add("IPM.Post.Account info")    oAccount.Display() End Sub      '****************************************************** 'Sub Actions_onClick(Action) ' 'This subroutine executes the correct action, such as 'finding an item, creating a new account, and so on, 'depending on what the user picked in the Web page. '****************************************************** Sub Actions_onClick(Action)    Select Case Action       Case "AddressBook"          oViewControl.AddressBook()       Case "AddtoFavorites"          oViewControl.AddtoFavorites()       Case "ExpandAllGroups"          oViewControl.ExpandAllGroups()       Case "CollapseAllGroups"          oViewControl.CollapseAllGroups()       Case "AdvancedFind"          oViewControl.AdvancedFind()       Case "CreateAccount"          CreateAccount()    End Select End Sub 

You can also take advantage of other methods and properties in your applications that use the Outlook View control. To see a complete list of them, just add a reference to the Outlook View control in the Object Browser in VBA or Visual Basic. Most of the methods and properties are self-explanatory ”for example, the ReplyInFolder and ReplyAll methods. Here are a few of the more interesting properties and methods for the View control that we haven't discussed yet:

  • FlagItem method     Opens a dialog box that flags an item with a reminder. This method will not work unless the user has selected a valid item in the View control, such as a PostItem.

  • Categories method     Opens the Categories dialog box, in which the user can select item categories. This is the same dialog box that appears when the Categories button is clicked in an Outlook form.

  • CustomizeView method     Opens a dialog box that lets a user select fields, the sort orders, the filters, the automatic formatting, and the grouping for the view. This is the same dialog box that appears when the user chooses Current View, Customize Current View from the View menu.

  • ShowFields method     Opens the Show Fields dialog box, where the user can quickly select fields for the View control to display for the current view.

  • SynchFolder method     Attempts to synchronize the current folder in the background. (I say attempts because your program might call this method only to find that the connection to the Exchange server is not available.) Consider creating a button on your HTML form so users can easily activate folder synchronization.

  • Restriction property     A powerful property that allows you to filter the items you want to display in your view. It takes the same string format as the Restrict method on the Items collection. For example, if you want to restrict the view so that only Task items appear, you pass to the Restriction property the following string: [Message Class] = "IPM.Task". You can also pass your restriction as a parameter by using the following syntax when you create your View control:

     <param NAME=Restrict VALUE="[Message Class] = 'IPM.Task'"> 

    By using the Restriction property, you can place two View controls on a single page and have one view control show a restricted set of items on the basis of what the users select in the other View control.




Programming Microsoft Outlook and Microsoft Exchange 2003
Programming MicrosoftВ® OutlookВ® and Microsoft Exchange 2003, Third Edition (Pro-Developer)
ISBN: 0735614644
EAN: 2147483647
Year: 2003
Pages: 227
Authors: Thomas Rizzo

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