How to use the Microsoft Outlook Object Library to retrieve an appointment by using Visual C#
2009. 2. 19. 10:15
아래 내용은 microsoft의 정보를 인용한 것입니다.
http://support.microsoft.com/kb/310259/en-us
To use the Outlook 2002 Object Library or the Outlook 2003 Object Library to retrieve an appointment in a Visual C# .NET project, follow these steps:
- In Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, create a new Console Application project:
- On the File menu, point to New, and then click Project.
- Under Project Types, click Visual C# Projects.
Note In Visual Studio 2005, click Visual C# under Project Types. - Under Templates, click Console Application.
- Click OK. By default, a file that is named Class1.cs is created.
Note In Microsoft Visual C# 2005, Program.cs is created by default.
- Add a reference to either the Outlook 2002 Object Library or the Outlook 2003 Object Library. To do this, follow these steps:
- On the Project menu, click Add Reference.
- Click the COM tab.
- On the COM tab, click Microsoft Outlook 11.0 Object Library if you are using Outlook 2003, or click Microsoft Outlook 10.0 Object Library if you are using Outlook 2002.
- Click Select.
Note In Visual Studio 2005, you do not have to click Select. - In the Add References dialog box, click OK.
Note If you receive a message to generate wrappers for the libraries that you selected, click Yes.
- In the Class1.cs code window, replace all the existing code with the following code:
using System; using System.Reflection; // to use Missing.Value //TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line. //using Outlook = Microsoft.Office.Interop.Outlook; namespace RetrieveAppointment { /// <summary> /// Summary description for Class1. /// </summary> public class Class1 { /// <summary> /// The main entry point for the application. /// </summary> public static int Main(string[] args) { try { // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Get the NameSpace and Logon information. // Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi"); Outlook.NameSpace oNS = oApp.GetNamespace("mapi"); //Log on by using a dialog box to choose the profile. oNS.Logon(Missing.Value, Missing.Value, true, true); //Alternate logon method that uses a specific profile. // TODO: If you use this logon method, // change the profile name to an appropriate value. //oNS.Logon("YourValidProfile", Missing.Value, false, true); // Get the Calendar folder. Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); // Get the Items (Appointments) collection from the Calendar folder. Outlook.Items oItems = oCalendar.Items; // Get the first item. Outlook.AppointmentItem oAppt = (Outlook.AppointmentItem) oItems.GetFirst(); // Show some common properties. Console.WriteLine("Subject: " + oAppt.Subject); Console.WriteLine("Organizer: " + oAppt.Organizer); Console.WriteLine("Start: " + oAppt.Start.ToString()); Console.WriteLine("End: " + oAppt.End.ToString()); Console.WriteLine("Location: " + oAppt.Location); Console.WriteLine("Recurring: " + oAppt.IsRecurring); //Show the item to pause. oAppt.Display(true); // Done. Log off. oNS.Logoff(); // Clean up. oAppt = null; oItems = null; oCalendar = null; oNS = null; oApp = null; } //Simple error handling. catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } //Default return value return 0; } } }
- In this code, make any necessary changes where you see the "TO DO" comments.
- Press F5 to build and then run the program. Outlook security features may display additional dialog boxes before the appointment information appears. (이부분 때문에 Object Library를 사용하면 안될 것 같다. 그럼? MAPI라는게 있는데 이걸 조사해 봐야겠다.)
For more information, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx (http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx)
For more information about the Outlook 2002 e-mail security features and about how those features can affect custom solutions, click the following article number to view the article in the Microsoft Knowledge Base:
290500 (http://support.microsoft.com/kb/290500/ ) Description of the developer-related e-mail security features in Outlook 2002