Creating an Outlook Contact

This migration tip shows how to create a Microsot Outlook contact using Microsoft Office Automation and Aspose.Email. The code sample shows how to set different information of a Contact such as Personal, Professional and Business information. Creating an Outlook contact consists of the following steps:
1. Creating a Contact object.
2. Populating or setting the property's various properties.
3. Saving the object.

VSTO

            //Create a new MapiContact Object
            MapiContact mapiContact = new MapiContact();

            //Set different properties of this Contact object
            mapiContact.NameInfo = new MapiContactNamePropertySet("Mellissa", "", "MacBeth");
            mapiContact.ProfessionalInfo.Title = "Account Representative";
            mapiContact.ProfessionalInfo.CompanyName = "Contoso Ltd.";
            mapiContact.ProfessionalInfo.OfficeLocation = "36/2529";
            mapiContact.Telephones.BusinessTelephoneNumber = "4255551212 x432";
            mapiContact.PhysicalAddresses.WorkAddress.Street = "1 Microsoft Way";
            mapiContact.PhysicalAddresses.WorkAddress.City = "Redmond";
            mapiContact.PhysicalAddresses.WorkAddress.StateOrProvince = "WA";
            mapiContact.PhysicalAddresses.WorkAddress.PostalCode = "98052";
            mapiContact.PhysicalAddresses.WorkAddress.Country = "United States of America";
            mapiContact.ElectronicAddresses.Email1.EmailAddress = "milissa@contoso.com";
            mapiContact.ElectronicAddresses.Email1.AddressType = "SMTP";
            mapiContact.ElectronicAddresses.Email1.DisplayName = "Melissa MacBeth (mellissa@contoso.com)";

            //Save the Contact object to disc
            mapiContact.Save("Contact.vcf", ContactSaveFormat.VCard);


Aspose.Email
            //Create a new MapiContact Object
            MapiContact mapiContact = new MapiContact();

            //Set different properties of this Contact object
            mapiContact.NameInfo = new MapiContactNamePropertySet("Mellissa", "", "MacBeth");
            mapiContact.ProfessionalInfo.Title = "Account Representative";
            mapiContact.ProfessionalInfo.CompanyName = "Contoso Ltd.";
            mapiContact.ProfessionalInfo.OfficeLocation = "36/2529";
            mapiContact.Telephones.BusinessTelephoneNumber = "4255551212 x432";
            mapiContact.PhysicalAddresses.WorkAddress.Street = "1 Microsoft Way";
            mapiContact.PhysicalAddresses.WorkAddress.City = "Redmond";
            mapiContact.PhysicalAddresses.WorkAddress.StateOrProvince = "WA";
            mapiContact.PhysicalAddresses.WorkAddress.PostalCode = "98052";
            mapiContact.PhysicalAddresses.WorkAddress.Country = "United States of America";
            mapiContact.ElectronicAddresses.Email1.EmailAddress = "milissa@contoso.com";
            mapiContact.ElectronicAddresses.Email1.AddressType = "SMTP";
            mapiContact.ElectronicAddresses.Email1.DisplayName = "Melissa MacBeth (mellissa@contoso.com)";

            //Save the Contact object to disc
            mapiContact.Save("Contact.vcf", ContactSaveFormat.VCard);


Download

Last edited Jan 1, 2014 at 6:38 AM by asposemarketplace, version 2