تخطي إلى المحتوى الرئيسي
الدعم
تسجيل الدخول باستخدام حساب Microsoft
تسجيل الدخول أو إنشاء حساب.
مرحباً،
تحديد استخدام حساب مختلف!
لديك حسابات متعددة
اختر الحساب الذي تريد تسجيل الدخول باستخدامه.

الملخص

تصف هذه المقالة كيفية استخدام مكتبة العناصر Outlook Microsoft 10.0 لاسترداد رسائل معينة باستخدام الأسلوب "البحث" وطريقة تقييد في Microsoft Visual C#.

مزيد من المعلومات

لاستخدام Microsoft Outlook 10.0 Object Library لاسترداد رسائل معينة، اتبع الخطوات التالية:

  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. إضافة مرجع إلى مكتبة Outlook Microsoft 10.0. للقيام بذلك، اتبع الخطوات التالية:

    1. في القائمة Project، انقر فوق إضافة مرجع.

    2. انقر فوق علامة التبويب COM، وحدد موقع Microsoft Outlook 10.0 Object Library، ثم انقر فوق تحديد.

      ملاحظة في Microsoft Visual C# 2005. لا تحتاج إلى النقر فوق تحديد.

    3. في مربع الحوار إضافة مراجع ، انقر فوق موافق.

    4. إذا تم مطالبتك بإنشاء مغلفات للمكتبات التي حددتها، انقر فوق نعم.

  5. في نافذة التعليمات البرمجية، استبدل التعليمة البرمجية بما يلي:

    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;
    }
    }
    }
  6. ابحث عن السلسلة النصية TODO في التعليمة البرمجية، ثم قم بتعديل التعليمة البرمجية بيئتك.

  7. اضغط على المفتاح F5 لإنشاء البرنامج وتشغيله.

المراجع

لمزيد من المعلومات حول ميزات الأمان في Outlook 2002، انقر فوق رقم المقالة التالية لعرض المقالة في قاعدة معارف Microsoft:

290500 وصف ميزات أمان البريد الإلكتروني ذات الصلة بالمطور في Outlook 2002


للحصول على معلومات إضافية حول المشاكل التي قد تحدث عند استخدام الخاصية Count للمجموعات الكبيرة، انقر فوق رقم المقالة التالية لعرض المقالة في قاعدة معارف Microsoft:

294385 OL2002: خاصية عدد غير صحيح باستخدام المواعيد المتكررة

هل تحتاج إلى مزيد من المساعدة؟

الخروج من الخيارات إضافية؟

استكشف مزايا الاشتراك، واستعرض الدورات التدريبية، وتعرف على كيفية تأمين جهازك، والمزيد.

تساعدك المجتمعات على طرح الأسئلة والإجابة عليها، وتقديم الملاحظات، وسماعها من الخبراء ذوي الاطلاع الواسع.

هل كانت المعلومات مفيدة؟

ما مدى رضاك عن جودة اللغة؟
ما الذي أثّر في تجربتك؟
بالضغط على "إرسال"، سيتم استخدام ملاحظاتك لتحسين منتجات Microsoft وخدماتها. سيتمكن مسؤول تكنولوجيا المعلومات لديك من جمع هذه البيانات. بيان الخصوصية.

نشكرك على ملاحظاتك!

×