Összefoglalás
Ez a cikk azt ismerteti, hogy miként lehet a Microsoft Outlook 10.0 objektumtár használatával adott üzeneteket beolvasni a Microsoft Visual C# keresés és a Korlátozás módszer használatával.
További információ
Ha a Microsoft Outlook 10.0 objektumtárat használva lekérni bizonyos üzeneteket, kövesse az alábbi lépéseket:
-
Indítsa el a Microsoft Visual Studio .NET vagy Microsoft Visual Studio 2005-öt.
-
A Fájl menüben mutasson az Új elemre, majd kattintson a Project.
-
A Visual C# Projects types (Visual C# Projektek típusa) listában kattintson a Console Application (Konzolalkalmazás) elemre.
Alapértelmezés szerint létrejön az Osztály1.cs fájl. Megjegyzés: A Microsoft Visual C# 2005-ben kattintson a Visual C#" gombra a Visual C# Projects types listában. Alapértelmezés szerint a Program.cs létrejön. -
Adjon hozzá egy hivatkozást a Microsoft Outlook 10.0 objektumtárhoz. Kövesse az alábbi lépéseket:
-
A Hivatkozás Project kattintson a Hivatkozás hozzáadása elemre.
-
Kattintson a COM fülre, keresse meg a Microsoft Outlook 10.0 objektumtárat, és kattintson a Kijelölés gombra.
Megjegyzés a Microsoft Visual C# 2005-ben. gombra, nem kell a Kijelölés gombra kattinta. -
A Hivatkozások hozzáadása párbeszédpanelen kattintson az OK gombra.
-
Ha a program arra kéri, hogy hozzon létre több wrappert a kijelölt tárakhoz, kattintson az Igen gombra.
-
-
A kódablakban cserélje le a kódot a következőre:
using System;
using System.Reflection; // to use Missing.Value namespace FilterAppointments { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] public static int Main(string[] args) { try { // Create an Outlook application. Outlook.Application oApp = new Outlook.Application(); // Get the Mapi NameSpace and the Logon. Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi"); // Log on using dialog to choose a profile. oNS.Logon(Missing.Value, Missing.Value, true, true); // Alternate Logon using specific profile // TODO: Change the profile name where it is appropriate. //oNS.Logon("YourValidProfile", Missing.Value, false, true); // Get the Calendar folder. Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); // Get the Items collection in the folder. Outlook.Items oItems = (Outlook.Items)oCalendar.Items; Console.WriteLine("Total Items (unrestricted): " + oItems.Count); //Include all occurrences of recurring items, and then sort them. oItems.Sort ("[Start]", false); oItems.IncludeRecurrences = true; // Define the string for the search criteria. String sCriteria; // Set the criteria for the Date fields. sCriteria = "[Start] <= '09/01/2002 08:00 AM' and [End] >= '2/15/2002 08:00 PM'"; // Set the criteria for a string field. // sCriteria = "[Subject] = 'Weekly recurring meeting'"; // Set the criteria for a numeric field. // Look for meetings that have not been responded to. // sCriteria = "[ResponseStatus] = " + (Int32)Outlook.OlResponseStatus.olResponseNotResponded) // Use the Restrict method to reduce the number of items to process. Outlook.Items oRestrictedItems = oItems.Restrict(sCriteria); oRestrictedItems.Sort ("[Start]", false); oRestrictedItems.IncludeRecurrences = true; Console.WriteLine("Total Items Unrestricted : " + oRestrictedItems.Count); Outlook.AppointmentItem oAppointment; //Get each item until item is null. Outlook.AppointmentItem oAppt; oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetFirst(); while (oAppt != null) { // Console.WriteLine(i.ToString()); Console.WriteLine(" Subject: " + oAppt.Subject.ToString()); Console.WriteLine(" Start time: " + oAppt.Start.ToString()); Console.WriteLine(" End time: " + oAppt.End.ToString()); Console.WriteLine(" Occurrences: " + oAppt.RecurrenceState.ToString()); Console.WriteLine("\n\n"); oAppt = (Outlook.AppointmentItem)oRestrictedItems.GetNext(); } // Use the Find method to get single match. sCriteria = "[Start] >= '09/30/2001'"; Console.WriteLine("Criteria: " + sCriteria.ToString()); oAppointment = (Outlook.AppointmentItem)oItems.Find(sCriteria); Console.WriteLine("Used Find with Date fields"); if (oAppointment is Outlook.AppointmentItem) Console.WriteLine("Found -> " + oAppointment.Subject.ToString()); else Console.WriteLine("No object found"); // Log off oNS.Logoff(); // Clean up oAppointment = null; oRestrictedItems = 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; } } } -
Keresse meg a TODO karakterláncot a kódban, majd módosítsa a környezet kódját.
-
A buildhez és a program futtatásához nyomja le az F5 billentyűt.
Hivatkozások
A Outlook 2002 biztonsági funkcióiról a következő cikkszámra kattintva olvashat bővebben a Microsoft Tudásbázisban:
290500 Az Outlook 2002 fejlesztői e-mail biztonsági funkcióinak leírása A nagy gyűjtemények Count tulajdonságának használata során esetleg előforduló problémákról további információt a következő cikkszámra kattintva olvashat a Microsoft Tudásbázisban:
294385 OL2002: Helytelen Count tulajdonság ismétlődő találkozók használatával