Adding Folder Home Pages


Folder home pages enable you to link an HTML page to any folder in the Outlook environment. Folder home pages support offline viewing capabilities, so you can ask Outlook to synchronize an HTML file that is associated with an offline folder when a user synchronizes the folder. This ensures that your HTML page is available whether the user is working off line or on line. We will look at two folder home pages in this chapter, one of which uses the Outlook View control.

The process of associating a folder home page with a folder is easy. Outlook provides a user interface for this connection, as shown in Figure 8-13. You can access this Properties dialog box in Outlook by right-clicking on a folder and then choosing Properties.

click to expand
Figure 8-13: Configuring a folder home page for a folder

Because Outlook hosts Internet Explorer in-frame, when a user clicks on the folder, your folder home page can appear directly inside the Outlook client. Furthermore, you can make the folder home page the default view for a particular folder. In the Web pages for your folder home pages, you might want to include instructions for using the folder, a way to mail the folder owner, or a list of links related to that folder or other folders.

You can also add script to the folder home page to access the Outlook object model. Figure 8-14 shows the first example of a custom folder home page (Contacts.htm) for the Account Tracking application.

click to expand
Figure 8-14: The folder home page (Contacts.htm) for the Account Tracking application

Setting Up the First Folder Home Page

To test the folder home pages, you need a machine that has Outlook with the Visual Basic Scripting Support and Collaboration Data Objects components installed. Follow these steps to set up the first folder home page:

  1. If you haven't already set up the Account Tracking application, do so now (as explained in the section titled "Setting Up the Account Tracking Application" earlier in this chapter). If you want the application to create sales charts and print account summaries, install Excel.

  2. If necessary, clear the read-only flag for the files contained in the Webview folder from the sample code.

  3. Open the Webview\Contacts.htm file in Notepad.

  4. Find the first occurrence of oAccountFolder and modify the path to the location of your Account Tracking folder.

  5. Save Contacts.htm and close Notepad.

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

  7. In the Address text box of the Home Page tab, specify the location of the Contacts.htm file ”for example, file://C:\Webview\Contacts.htm .

  8. Select the Show Home Page By Default For This Folder option, and then click OK.

  9. Click the Account Tracking folder in Outlook to display the folder home page. You will be prompted to allow access for an item to your address book. This prompt is triggered because the folder home page scans all the accounts to look for the current user as a team member on an account. This triggers the Outlook security dialog box.

Sample Script for the Folder Home Page

The following code shows the script for the folder home page (Contacts.htm) shown earlier in Figure 8-14:

 <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")      'Change this to your location for the Account Tracking folder Set oAccountFolder = oNS.Folders("Public Folders").Folders( _    "All Public Folders").Folders("Account Tracking")      'Set some global vars for the EntryIDs Dim arrTaskEntryIDs() Dim oTasks    'Restricted collection of Tasks Dim arrAccountEntryIDs() Dim oAccounts    'Restricted collection of Accounts      '****************************************************** '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 GetTask(lEntryID) ' 'This subroutine gets the task that the user clicked on 'in the HTML page and displays it. An index into an 'array of EntryIDs is passed to this subroutine. '****************************************************** Sub GetTask(lEntryID)    lTaskEntryID = arrTaskEntryIDs(lEntryID-1)    For Each oItem In oTasks       If oItem.EntryID = lTaskEntryID Then          Set otmpTask = oItem       End If    Next    otmpTask.Display() End Sub      '****************************************************** 'Sub GetAccount(lEntryID) ' 'This subroutine gets the account that the user clicked on 'in the HTML page and displays it. An index into an 'array of EntryIDs is passed to this subroutine. '****************************************************** Sub GetAccount(lEntryID)    lAccountEntryID = arrAccountEntryIDs(lEntryID-1)    For Each oItem In oAccounts       If oItem.EntryID = lAccountEntryID Then          Set otmpAccount = oItem       End If    Next    otmpAccount.Display() End Sub      Sub Window_onLoad() '**************************************************************** 'All of the following lines are run when the HTML page is 'loaded '****************************************************************    'Put the name of the folder in the bar    txtFolder.innerHTML = oAccountFolder.Name & " Folder"      '**************************************************************** 'Figure out the account tasks for the current user '****************************************************************    RestrictString = ""    RestrictString = "[Message Class] = ""IPM.Task""" & _       " AND [Owner] = """ & oNS.CurrentUser.Name & """ AND _         [Complete] = FALSE"    Set oTasks = oAccountFolder.Items.Restrict(RestrictString)    oTasksCount = oTasks.Count    'Redim the EntryID array    ReDim arrTaskEntryIDs(oTasksCount-1)    strTaskList = "<TABLE Border=0 cellpadding=2 cellspacing=2 " & _    "class='calendarinfo'><TR><TD><strong><Font Size=2><U>" & _    "Account Name</u></STRONG></TD><TD>&nbsp;&nbsp;</TD><TD>" & _    "<STRONG><Font size=2><U>Task Name</U></FONT></STRONG>" & _    "</TD><TD>&nbsp;&nbsp;</TD><TD><STRONG><Font size=2><U>" & _    "(Due Date)</U></FONT></strong></TD></TR>"    'Count the tasks using counter    counter = 1    oTasks.Sort "[ConversationTopic]", False    For Each oTask in oTasks       boolOverDue = 0       If oTask.DueDate = "1/1/4501" Then          strDueDate = "None"       Else          strDueDate = oTask.DueDate          'Check to see whether the task is overdue          If DateDiff("d",CDate(strDueDate),Now) > 0 Then             boolOverDue = 1          End If       End If       If boolOverDue Then          'Turn red          strTaskList = strTaskList & "<TR><TD><FONT " & _          "COLOR='#FF0000'><STRONG>" & oTask.ConversationTopic & _          "</STRONG></FONT></TD><TD>&nbsp;&nbsp;</TD><TD>" & _          "<A HREF='' onclick=GetTask(" & counter & _          ");window.event.returnValue=false>" & oTask.Subject & _          "</a></TD><TD>&nbsp;&nbsp;</TD><TD><FONT " & _          "COLOR='#FF0000'>(<Strong>" & strDueDate & _          "</Strong>)</FONT><BR></TD></TR>"       Else          strTaskList = strTaskList & "<TR><TD><STRONG>" & _          oTask.ConversationTopic & "</STRONG></TD><TD>" & _          "&nbsp;&nbsp;</TD><TD><A HREF='' onclick=GetTask(" & _          "counter & ");window.event.returnValue=false>" & _          oTask.Subject & "</a></TD><TD>&nbsp;&nbsp;</TD>" & _          "<TD>(<Strong>" & strDueDate & "</Strong>)<BR></TD></TR>"       End If       arrTaskEntryIDs(counter-1) = oTask.EntryID       counter = counter + 1    Next    TaskList.innerHTML = strTaskList & "</TABLE>"      '**************************************************************** 'Figure out which accounts the current user is a team member of '****************************************************************         'Find accounts where this person is a team member.    'First restrict to only account items.    RestrictString = ""    RestrictString = "[Message Class] = "IPM.Post.Account info""    Set oAccounts = oAccountFolder.Items.Restrict(RestrictString)         'Now find accounts where this person is a team member    numFound = 0    strCurrentUser = oNS.CurrentUser.Name    numTotalRevenue = 0    strAccountHTML = "<table border=0 width=100% cellpadding=3 " & _    "cellspacing=0 ID='Home' style='DISPLAY: inline; " & _    "MARGIN-TOP: 12px'>"    strAccountHTML = strAccountHTML & "<TR><TD " & _    "class='calendarinfo'><STRONG><FONT SIZE=2><U>Account Name" & _    "</U></FONT></STRONG></TD></TR>"         RestrictString = ""    RestrictString = "[Message Class] = ""IPM.Post.Account info""" & _    " AND [txtAccountConsultant] = """ & strCurrentUser & _    """ OR [txtAccountExecutive] = """ & strCurrentUser & _    """ OR [txtAccountSalesRep] = """ & strCurrentUser & _    """ OR [txtAccountSE] = """ & strCurrentUser & _    """ OR [txtAccountSupportEngineer] = """ & strCurrentUser & """"         Set oAccounts = oAccountFolder.Items.Restrict(RestrictString)    numFound = oAccounts.Count    ReDim arrAccountEntryIDs(numFound)    counter = 1    For Each oAccount in oAccounts       Set oUserProps = oAccount.UserProperties       arrAccountEntryIDs(counter-1) = oAccount.EntryID       'Get the total revenue for the account for 1998 and 1999.       'Get the revenue and add it to the total.       num1998Total = oUserProps.Find("form1998ActualTotal")       num1999Total = oUserProps.Find("form1999ActualTotal")       If num1998Total <> "Zero" Then          numTotalRevenue = numTotalRevenue + num1998Total       End If       If num1999Total <> "Zero" Then          numTotalRevenue = numTotalRevenue + num1999Total       End If       strAccountHTML = strAccountHTML & "<TR><TD " & _       "class='calendarinfo'><A Href='' onclick=GetAccount(" & _         "counter & ");window.event.returnValue=false>" & _       oAccount.Subject & "</A></TD></TR>"       counter = counter + 1    Next    numTotalRevenue = CCur(numTotalRevenue)    numTotalRevenue = FormatCurrency(numTotalRevenue)    TotalRevenue.innerHTML = "<STRONG>" & numTotalRevenue & _       "</STRONG>"    strAccountHTML = strAccountHTML & "</TABLE>"    Accounts.innerHTML = strAccountHTML    YourTasks.innerHTML = "<Strong>" & oTasksCount & "</Strong>"    YourAccounts.innerHTML = "<STRONG>" & numFound & "</STRONG>" End Sub    'Window_OnLoad --> </SCRIPT> 

You can see that you need to follow a few critical steps to access the Outlook object model. The first step is to retrieve the Outlook Application object. To do this, you use the Window.External.OutlookApplication syntax. You can then retrieve the rest of the Outlook objects. For example, by calling the ActiveExplorer method on the Application object that's returned, you can retrieve the Explorer object that is hosting the folder home page.

The folder home page is a dynamic environment for viewing a folder, as illustrated by the folder home page used in the Account Tracking application. On the home page, the user is presented with a summary of her accounts, account revenue, and tasks. The home page allows you to restrict account tasks to the person currently viewing the folder. (You could create a similar view in Outlook, but you wouldn't be able to specify a filter for who can view the folder.) These account summaries are created by using the Restrict method on the Outlook Items collection for the folder. For the Tasks restriction, the code restricts only those messages in the folder that are tasks, and where the current user is the owner and the task status is incomplete. After receiving the restricted set, the code sorts the tasks by their conversation topics, which are the names of the accounts the tasks are for. The code loops through each task to see whether it has a due date. If it does, the code checks to see whether the task is past due. Then the code generates the HTML, which is placed in the Open Account Tasks list.

For the revenue summary, the code first finds all account items to tally a total. The code restricts the collection to all accounts for which the current user is a team member. Then the code loops through each account and retrieves the revenue, which is stored in the UserProperties collection as custom properties. Because the revenue properties are formula properties, they can contain text that indicates zero revenue from the account. To compensate for this, the code checks whether the value of the property is the string " Zero". The code then builds a string for the restricted list of account names and prints out the account revenue. The string of account names is hyperlinked, as are the tasks, so that a user can quickly go to a specific account or task.

From the code sample, you can see how you can include the features of the Outlook object model, or any object model for that matter, inside the HTML page you create for your folders.




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