דלג לתוכן הראשי
היכנס דרך Microsoft
היכנס או צור חשבון.
שלום,
בחר חשבון אחר.
יש לך חשבונות מרובים
בחר את החשבון שברצונך להיכנס באמצעותו.

סיכום

מאמר זה מתאר כיצד להשתמש בספריית האובייקטים של 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 ספריית אובייקטים ולאחר מכן לחץ על בחר.

      הערה ב- 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 Knowledge Base:

290500 תיאור של תכונות האבטחה הקשורות למפתחים בדואר אלקטרוני ב- Outlook 2002


לקבלת מידע נוסף אודות בעיות שעלולות להתרחש בעת שימוש במאפיין Count של אוספים גדולים, לחץ על מספר המאמר הבא כדי להציג את המאמר הרלוונטי מתוך Microsoft Knowledge Base:

294385 OL2002: מאפיין ספירה שגויה באמצעות פעילויות חוזרות

זקוק לעזרה נוספת?

מעוניין באפשרויות נוספות?

גלה את יתרונות המנוי, עיין בקורסי הדרכה, למד כיצד לאבטח את המכשיר שלך ועוד.

קהילות עוזרות לך לשאול שאלות ולהשיב עליהן, לתת משוב ולשמוע ממומחים בעלי ידע עשיר.

האם מידע זה היה שימושי?

עד כמה אתם מרוצים מאיכות השפה?
מה השפיע על החוויה שלך?
בלחיצה על 'שלח', אתה מאפשר למשוב שלך לשפר מוצרים ושירותים של Microsoft. מנהל ה-IT שלך יוכל לאסוף נתונים אלה. הצהרת הפרטיות.

תודה על המשוב!

×