How to use the Microsoft Outlook Object Library to create an Outlook contact in Visual Basic .NET

This article was previously published under Q313787
This article has been archived. It is offered "as is" and will no longer be updated.
This article describes how to use the Microsoft Outlook Object Library to create a contact in Microsoft Visual Basic .NET.

This article assumes that you are familiar with the following topics:
  • Outlook Object Model (OOM)
  • Programming with Visual Basic .NET
To use the Microsoft Outlook Object Library to create a contact in Microsoft Visual Basic .NET, follow these steps:
  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Under Project Types, click Visual Basic Projects.
  4. Under Templates, click Console Application, and then click OK.

    By default, Module1.vb is created.
  5. Add a reference to the Microsoft Outlook 10.0 Object Library. To do this, follow these steps:
    1. On the Project menu, click Add Reference.
    2. On the COM tab, click Microsoft Outlook 10.0 Object Library, and then click Select.
    3. In the Add References dialog box, click OK to accept your selections. If you receive a prompt to generate wrappers for the libraries that you selected, click Yes.
  6. In the code window for Module1, replace all the code with:
    'TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.'Imports Outlook = Microsoft.Office.Interop.OutlookImports System.ReflectionModule Module1    Sub Main()        ' Create an Outlook application.        Dim oApp As Outlook.Application = New Outlook.Application()        ' Get the namespace and the logon.        Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")        ' TODO: Replace the "YourValidProfile" and "myPassword" with         'Missing.Value if you want to log on with the default profile.        oNS.Logon("YourValidProfile", "myPassword", True, True)        ' Create a new contact item.        Dim oCt As Outlook.ContactItem = oApp.CreateItem(Outlook.OlItemType.olContactItem)        oCt.Display(True)  'Modal	        ' Set some common properties.        oCt.FullName = "David Pelton"        oCt.Title = "Student"        oCt.Birthday = Convert.ToDateTime("10/1/1982")        oCt.CompanyName = "Fourth Coffee "        oCt.Department = "PSS"        oCt.Body = "Test Body"        oCt.FileAs = "David"        oCt.Email1Address = ""        oCt.BusinessHomePage = ""        oCt.MailingAddress = "12345 Bellevue"        oCt.BusinessAddress = "56789 1st. Redmond, WA 98001"        oCt.OfficeLocation = "666 Office"        oCt.Subject = "Hello World"        oCt.JobTitle = "Engineer"        ' Save it to the Contacts folder.        oCt.Save()        ' Display the created contact item.        'oCt.Display(True)        ' Log off.        oNS.Logoff()        ' Clean up.        oApp = Nothing        oNS = Nothing        oCt = Nothing    End SubEnd Module
  7. Search for "TO DO" in the code, and then modify the code for your environment.
  8. Press F5 to build and to run the program.
  9. Verify that the contact has been created.
For more information about the security-enhancing features of Outlook 2002, click the following article number to view the article in the Microsoft Knowledge Base:
290500 Description of the developer-related e-mail security features in Outlook 2002
vbnet oom

Article ID: 313787 - Last Review: 12/07/2015 08:15:51 - Revision: 2.4

Microsoft Visual Basic .NET 2002 Standard Edition, Microsoft Visual Basic .NET 2003 Standard Edition, Microsoft Outlook 2002 Standard Edition, Microsoft Office Outlook 2003

  • kbnosurvey kbarchive kbhowtomaster KB313787