Microsoft Office Tutorials and References
In Depth Information
Contacts
You have seen how to create a new contact item by using an object in Outlook
2007. Let's take a look at one of the most important contact management features in
Microsoft Office Outlook: the distribution list. A distribution list is a collection of
email contact information that has been grouped into a single list. VSTO helps Office
developers create and modify distribution lists by using the DistListItem object.
Let's create a distribution list dynamically, using the VSTO Outlook object model and
C# programming.
Open Visual Studio 2008 and create a new solution, as described earlier.
Write the following code, which will dynamically create a distribution list, inside
the ThisAddIn.cs file:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// Using the Outlook object reading through the Distribution item
// Preparing to create a new Distribution item
Outlook.DistListItem OutlookPacktDistributionList = (Outlook.
DistListItem)this.Application.CreateItem(Outlook.OlItemType.
olDistributionListItem);
// Name the new distribution list
OutlookPacktDistributionList.DLName = "PacktContactList";
// To set the recipient information, create the mailitem
collect object
Outlook.MailItem PacktListItem = (Outlook.MailItem)this.
Application.CreateItem(Outlook.OlItemType.olMailItem);
// Adding mail items
PacktListItem.Recipients.Add("Radhika Rajagopalan
<radhika@bookvsto.com>");
PacktListItem.Recipients.Add("Vivek Thangaswamy
<vivek@bookvsto.com>");
// Adding the recipients to the new distribution
OutlookPacktDistributionList.AddMembers(PacktListItem.Recipients);
// Save the new distribution using Save method
OutlookPacktDistributionList.Save();
}
 
Search JabSto ::




Custom Search