Загальні відомості

У цій статті описано, як за допомогою бібліотеки об'єктів Microsoft Outlook 10.0 отримати певні повідомлення за допомогою методу Знайти та Обмежити в Microsoft Visual C#.

Додаткові відомості

Щоб отримати певні повідомлення за допомогою бібліотеки об'єктів Microsoft Outlook 10.0, виконайте такі дії:

  1. Запустіть програму Microsoft Visual Studio .NET або Microsoft Visual Studio 2005.

  2. У меню Файл наведіть вказівник миші на пункт Створити та виберіть Project.

  3. У списку Типи проектів Visual C# клацніть Консольна програма. За замовчуванням створюється файл Class1.cs.Примітка. У Microsoft Visual C# 2005 виберіть Visual C#" у списку типів проектів Visual C #. За замовчуванням створюється program.cs.

  4. Додайте посилання на бібліотеку об'єктів Microsoft Outlook 10.0. Для цього виконайте такі дії:

    1. У меню Project клацніть Додати посилання.

    2. Перейдіть на вкладку COM, знайдіть пункт Microsoft Outlook 10.0 Object Library і натисніть кнопку Вибрати. Примітка. У Microsoft Visual C# 2005. не потрібно натиснути кнопку Вибрати.

    3. У діалоговому вікні Додавання посилань натисніть кнопку OK.

    4. Якщо буде запропоновано створити обтікання для вибраних бібліотек, натисніть кнопку Так.

  5. У вікні коду замініть код на такий:

    using System;using System.Reflection;     // to use Missing.Valuenamespace 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;      }   }}
  6. Знайдіть текстовий рядок TODO в коді, а потім змініть код свого середовища.

  7. Натисніть клавішу F5, щоб створити та запустити програму.

Посилання

Щоб отримати додаткові відомості про функції безпеки Outlook 2002, клацніть номер статті в базі знань Microsoft Knowledge Base:

290500 Опис функцій безпеки електронної пошти, пов'язаних із розробником у Outlook 2002. Щоб отримати додаткові відомості про проблеми, які можуть виникнути під час використання властивості Count великих колекцій, клацніть номер статті в базі знань Microsoft:

294385 OL2002: Неправильна властивість Count із повторюваними зустрічами

Потрібна додаткова довідка?

Потрібні додаткові параметри?

Ознайомтеся з перевагами передплати, перегляньте навчальні курси, дізнайтесь, як захистити свій пристрій тощо.