Article ID: 313787
Article Last Modified on 3/15/2006
APPLIES TO
- Microsoft Visual Basic .NET 2002 Standard Edition
- Microsoft Visual Basic .NET 2003 Standard Edition
- Microsoft Outlook 2002 Standard Edition
- Microsoft Office Outlook 2003
This article was previously published under Q313787
SUMMARY
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
MORE INFORMATION
To use the Microsoft Outlook Object Library to create a contact in Microsoft Visual Basic .NET, follow these steps:
- Start Microsoft Visual Studio .NET.
- On the File menu, point to New, and then click Project.
- Under Project Types, click Visual Basic Projects.
- Under Templates, click Console Application, and then click OK.
By default, Module1.vb is created. - Add a reference to the Microsoft Outlook 10.0 Object Library. To do this, follow these steps:
- On the Project menu, click Add Reference.
- On the COM tab, click Microsoft Outlook 10.0 Object Library, and then click Select.
- 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.
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.Outlook Imports System.Reflection Module 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 = "abc@hotmail.com" oCt.BusinessHomePage = "http://www.fourthcoffee.com/" 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 Sub End Module
- Search for "TO DO" in the code, and then modify the code for your environment.
- Press F5 to build and to run the program.
- Verify that the contact has been created.
REFERENCES
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
Additional query words: vbnet oom vb.net
Keywords: kbhowtomaster KB313787