Een Outlook‑contact maken
Deze migratietip toont hoe een Microsoft Outlook‑contact te maken met behulp van Microsoft Office‑automatisering en Aspose.Email. Het code‑voorbeeld toont hoe verschillende gegevens van een contact, zoals persoonlijke, professionele en zakelijke informatie, in te stellen. Het maken van een Outlook‑contact bestaat uit de volgende stappen:
- Een contactobject maken.
- Het invullen of instellen van de verschillende eigenschappen van het object.
- Het object opslaan.
Office‑automatisering
Om Office Automation te gebruiken, moet Microsoft Outlook geïnstalleerd zijn op de machine waarop de code wordt uitgevoerd. Een verwijzing naar Outlook.interop.dll is ook vereist.
Programmeer Voorbeelden
Het volgende code‑fragment maakt een Outlook‑contact in VCard‑formaat en slaat het op schijf op met behulp van Office Automation.
C#
Microsoft.Office.Interop.Outlook._Application OutlookObject = new Microsoft.Office.Interop.Outlook.Application();
//Create a new Contact Item
Microsoft.Office.Interop.Outlook.ContactItem contact = OutlookObject.CreateItem(
Microsoft.Office.Interop.Outlook.OlItemType.olContactItem);
//Set different properties of this Contact Item.
contact.FirstName = "Mellissa";
contact.LastName = "MacBeth";
contact.JobTitle = "Account Representative";
contact.CompanyName = "Contoso Ltd.";
contact.OfficeLocation = "36/2529";
contact.BusinessTelephoneNumber = "4255551212 x432";
contact.BusinessAddressStreet = "1 Microsoft Way";
contact.BusinessAddressCity = "Redmond";
contact.BusinessAddressState = "WA";
contact.BusinessAddressPostalCode = "98052";
contact.BusinessAddressCountry = "United States of America";
contact.Email1Address = "melissa@contoso.com";
contact.Email1AddressType = "SMTP";
contact.Email1DisplayName = "Melissa MacBeth (mellissa@contoso.com)";
//Save the Contact to disc
contact.SaveAs("OutlookContact.vcf", OlSaveAsType.olVCard);
Aspose.Email voor Java
De onderstaande voorbeelden gebruiken Aspose.Email om het Outlook‑contact in VCard‑formaat te maken en op schijf op te slaan. Het voorbeeld toont hoe een contact te maken met de MapiContact klasse en het instellen van de contactgegevens in het object voordat het contact wordt opgeslagen.
Programmeer Voorbeelden
//Create a new MapiContact Object
MapiContact mapiContact = new MapiContact();
//Set different properties of this Contact object
mapiContact.setNameInfo(new MapiContactNamePropertySet("Mellissa", "", "MacBeth"));
mapiContact.getProfessionalInfo().setTitle("Account Representative");
mapiContact.getProfessionalInfo().setCompanyName("Contoso Ltd.");
mapiContact.getProfessionalInfo().setOfficeLocation("36/2529");
mapiContact.getTelephones().setBusinessTelephoneNumber("4255551212 x432");
mapiContact.getPhysicalAddresses().getWorkAddress().setStreet("1 Microsoft Way");
mapiContact.getPhysicalAddresses().getWorkAddress().setCity("Redmond");
mapiContact.getPhysicalAddresses().getWorkAddress().setStateOrProvince("WA");
mapiContact.getPhysicalAddresses().getWorkAddress().setPostalCode("98052");
mapiContact.getPhysicalAddresses().getWorkAddress().setCountry("United States of America");
mapiContact.getElectronicAddresses().getEmail1().setEmailAddress("milissa@contoso.com");
mapiContact.getElectronicAddresses().getEmail1().setAddressType("SMTP");
mapiContact.getElectronicAddresses().getEmail1().setDisplayName("Melissa MacBeth (mellissa@contoso.com)");
//Save the Contact object to disc
mapiContact.save("Contact.vcf", ContactSaveFormat.VCard);