Help and Support
 

powered byLive Search

HOW TO: Retrieve Appointments by Using the Outlook Object Model in Visual Basic .NET

Article ID:313801
Last Review:June 29, 2007
Revision:5.2
This article was previously published under Q313801
On This Page

SUMMARY

This article describes how to use Microsoft Outlook 10.0 Object Library to retrieve appointments in Visual Basic .NET.

Back to the top

Create the Sample to Retrieve Appointments

1.Start Microsoft Visual Studio .NET.
2.On the File menu, point to New, and then click Project.
3.Click Visual Basic Projects under Project Types, and then click Console Application under Templates. By default, Module1.vb is created.
4.Add a reference to the Microsoft Outlook 10.0 Object Library. To do this, follow these steps:
a. On the Project menu, click Add Reference.
b. Click the COM tab.
c. Click Microsoft Outlook 10.0 Object Library, and then click Select
d. Click OK. If you are prompted to generate wrappers for the library that you selected, click Yes.
5.In the Code window, replace the default code with the following code:
Imports System.Reflection

Module Module1

    Sub Main()
       ' Create Outlook application.
        Dim oApp As Outlook.Application = New Outlook.Application()

        ' Get NameSpace and Logon.
        Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
        oNS.Logon("YourValidProfile", Missing.Value, False, True) ' TODO:

        ' Get Appointments collection from the Calendar folder.
        Dim oCalendar As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
        Dim oItems As Outlook.Items = oCalendar.Items

        ' TODO: You may want to use Find or Restrict to retrieve the appointment that you prefer.
        ' ...

        ' Get the first AppointmentItem.
        Dim oAppt As Outlook.AppointmentItem = oItems.GetFirst()

        ' Display some common properties.
        Console.WriteLine(oAppt.Organizer)
        Console.WriteLine(oAppt.Subject)
        Console.WriteLine(oAppt.Body)
        Console.WriteLine(oAppt.Location)
        Console.WriteLine(oAppt.Start.ToString())
        Console.WriteLine(oAppt.End.ToString())

        ' Display.
        'oAppt.Display(true)

        ' Log off.
        oNS.Logoff()

        ' Clean up.
        oApp = Nothing
        oNS = Nothing
        oItems = Nothing
        oAppt = Nothing
    End Sub

End Module
					
6.Modify the code where you see the TODO comments.
7.Press F5 to build and to run the application.
8.Verify that the first appointment is retrieved.

Back to the top

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site:
Microsoft Office Development with Visual Studio
http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx (http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx)

Back to the top


APPLIES TO
Microsoft Visual Basic .NET 2002 Standard Edition
Microsoft Outlook 2002 Standard Edition
Microsoft .NET Framework Software Development Kit 1.0 Service Pack 2

Back to the top

Keywords: 
kbhowtomaster KB313801

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.