|
1. In Solution Explorer, right click MapIt.cs or MapIt.vb, and then click View Code.
MapIt.cs or MapIt.vb opens in the code editor.
2. Add the following code to the Microsoft.Office.Tools.Outlook.FormRegionControl.BeforeStartup event handler. The add-in raises the Microsoft.Office.Tools.Outlook.FormRegionControl.BeforeStartup event when the user opens a contact item. The following code determines whether the contact item contains an address. If the contact item does not contain an address, this code sets the Microsoft.Office.Tools.Outlook.FormRegionBeforeStartupEventArgs.Cancel property of the Microsoft.Office.Tools.Outlook.FormRegionBeforeStartupEventArgs class to true and the form region is not displayed. Otherwise, the add-in raises the Microsoft.Office.Tools.Outlook.FormRegionControl.Startup event and displays the form region.
[Visual Basic]
Private Sub MapIt_BeforeStartup(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Outlook.FormRegionBeforeStartupEventArgs) Handles MyBase.BeforeStartup
Dim myItem As Outlook.ContactItem = CType(e.OutlookItem, Outlook.ContactItem)
If Not (myItem Is Nothing) Then
If Not (myItem.BusinessAddress Is Nothing) And myItem.BusinessAddress.Trim().Length > 0 Or (Not (myItem.HomeAddress Is Nothing) And myItem.HomeAddress.Trim().Length > 0) Or (Not (myItem.OtherAddress Is Nothing) And myItem.OtherAddress.Trim().Length > 0) Then
Return
End If
End If
e.Cancel = True
End Sub
[C#]
private static void MapIt_BeforeStartup(object sender, Microsoft.Office.Tools.Outlook.FormRegionBeforeStartupEventArgs e)
{
Outlook.ContactItem myItem = (Outlook.ContactItem)e.OutlookItem;
if (myItem != null)
{
if ((myItem.BusinessAddress != null && myItem.BusinessAddress.Trim().Length > 0) || (myItem.HomeAddress != null && myItem.HomeAddress.Trim().Length > 0) || (myItem.OtherAddress != null && myItem.OtherAddress.Trim().Length > 0))
{
return;
}
}
e.Cancel = true;
}
3. Add the following code to the Microsoft.Office.Tools.Outlook.FormRegionControl event handler. This code performs the following tasks:
· Concatenates each address in the contact item and creates a URL string.
· Calls the System.Windows.Forms.WebBrowser.Navigate method of the System.Windows.Forms.WebBrowser object and passes the URL string as a parameter.
The Live Local Web site appears in the Map It form region and presents each address in the Live Local Scratch pad.
[Visual Basic]
Private Sub MapIt_Startup(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Startup
Dim tempLoc As String = ""
Dim defaultAddress As String = ""
Dim scratchPadAddress As String = ""
Dim myItem As Outlook.ContactItem = CType(Me.OutlookItem, Outlook.ContactItem)
If Not (myItem Is Nothing) Then
If Not (myItem.HomeAddress Is Nothing) And myItem.HomeAddress.Trim().Length > 0 Then
tempLoc = myItem.HomeAddressStreet.Trim() + " " + myItem.HomeAddressCity + " " + myItem.HomeAddressState + " " + myItem.HomeAddressPostalCode
If myItem.HomeAddress = myItem.MailingAddress Then
defaultAddress = tempLoc + "_Home"
Else
scratchPadAddress += "adr." + tempLoc + "_Home~"
End If
End If
If Not (myItem.BusinessAddress Is Nothing) And myItem.BusinessAddress.Trim().Length > 0 Then
tempLoc = myItem.BusinessAddressStreet.Trim() + " " + myItem.BusinessAddressCity + " " + myItem.BusinessAddressState + " " + myItem.BusinessAddressPostalCode
If myItem.BusinessAddress = myItem.MailingAddress Then
defaultAddress = tempLoc + "_Business"
Else
scratchPadAddress += "adr." + tempLoc + "_Business~"
End If
End If
If Not (myItem.OtherAddress Is Nothing) And myItem.OtherAddress.Trim().Length > 0 Then
tempLoc = myItem.OtherAddressStreet.Trim() + " " + myItem.OtherAddressCity + " " + myItem.OtherAddressState + " " + myItem.OtherAddressPostalCode
If myItem.OtherAddress = myItem.MailingAddress Then
defaultAddress = tempLoc + "_Other"
Else
scratchPadAddress += "adr." + tempLoc + "_Other~"
End If
End If
End If
WebBrowser1.Navigate(("http://local.live.com/default.aspx?style=r&where1=" + defaultAddress + "&sp=" + scratchPadAddress))
End Sub
[C#]
private void MapIt_Startup(object sender, EventArgs e)
{
string tempLoc = "";
string defaultAddress = "";
string scratchPadAddress = "";
Outlook.ContactItem myItem = (Outlook.ContactItem)this.OutlookItem;
if (myItem != null)
{
if (myItem.HomeAddress != null && myItem.HomeAddress.Trim().Length > 0)
{
tempLoc = myItem.HomeAddressStreet.Trim() + " " + myItem.HomeAddressCity + " " + myItem.HomeAddressState + " " + myItem.HomeAddressPostalCode;
if (myItem.HomeAddress == myItem.MailingAddress)
{
defaultAddress = tempLoc + "_Home";
}
else
{
scratchPadAddress += "adr." + tempLoc + _Home~";
}
}
if (myItem.BusinessAddress != null && myItem.BusinessAddress.Trim().Length > 0)
{
tempLoc = myItem.BusinessAddressStreet.Trim() + " " + myItem.BusinessAddressCity + " " + myItem.BusinessAddressState + " " + myItem.BusinessAddressPostalCode;
if (myItem.BusinessAddress == myItem.MailingAddress)
{
defaultAddress = tempLoc + "_Business";
}
else
{
scratchPadAddress += "adr." + tempLoc + "_Business~";
}
}
if (myItem.OtherAddress != null && myItem.OtherAddress.Trim().Length > 0)
{
tempLoc = myItem.OtherAddressStreet.Trim() + " " + myItem.OtherAddressCity + " " + myItem.OtherAddressState + " " + myItem.OtherAddressPostalCode;
if (myItem.OtherAddress == myItem.MailingAddress)
{
defaultAddress = tempLoc + "_Other";
}
else
{
scratchPadAddress += "adr." + tempLoc + "_Other~";
}
}
}
webBrowser1.Navigate("http://local.live.com/default.aspx?style=r&where1=" + defaultAddress + "&sp=" + scratchPadAddress);
} |