3

C# を使用して、Outlook の予定を日付別に一覧表示 (抽出) したいと考えています。私はそれを行うためにrestrictメソッドを使用しました、

  sSearch = "[Start] >= ' " + startDate + " ' and [Start] <= ' " + endDate + " '";

ただし、終了日 (endDate) の翌日に終日の予定がある場合は、それもリストされます。この問題からどのように克服するのですか????

4

2 に答える 2

5

http://msdn.microsoft.com/en-us/library/office/gg619398(v=office.14).aspx

 private void DemoAppointmentsInRange()
{
    Outlook.Folder calFolder =
        Application.Session.GetDefaultFolder(
        Outlook.OlDefaultFolders.olFolderCalendar)
        as Outlook.Folder;
    DateTime start = DateTime.Now;
    DateTime end = start.AddDays(5);
    Outlook.Items rangeAppts = GetAppointmentsInRange(calFolder, start, end);
    if (rangeAppts != null)
    {
        foreach (Outlook.AppointmentItem appt in rangeAppts)
        {
            Debug.WriteLine("Subject: " + appt.Subject 
                + " Start: " + appt.Start.ToString("g"));
        }
    }
}

/// <summary>
/// Get recurring appointments in date range.
/// </summary>
/// <param name="folder"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns>Outlook.Items</returns>
private Outlook.Items GetAppointmentsInRange(
    Outlook.Folder folder, DateTime startTime, DateTime endTime)
{
    string filter = "[Start] >= '"
        + startTime.ToString("g")
        + "' AND [End] <= '"
        + endTime.ToString("g") + "'";
    Debug.WriteLine(filter);
    try
    {
        Outlook.Items calItems = folder.Items;
        calItems.IncludeRecurrences = true;
        calItems.Sort("[Start]", Type.Missing);
        Outlook.Items restrictItems = calItems.Restrict(filter);
        if (restrictItems.Count > 0)
        {
            return restrictItems;
        }
        else
        {
            return null;
        }
    }
    catch { return null; }
}
于 2013-01-10T06:09:48.210 に答える
2

タムタムに似ています。少し少ないコードです。LinqPad で使用できる基本的なサンプルを 1 日中探しました。これが私が最終的に得たものです。

//using Microsoft.Office.Interop.Outlook
Application a = new Application();
Items i = a.Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar).Items;
i.IncludeRecurrences = true;
i.Sort("[Start]");
i = i.Restrict("[Start] >= '10/1/2013' AND [End] <= '10/2/2013'");
var r =
    from ai in i.Cast<AppointmentItem>()
    select new {ai.Start,ai.Duration,ai.Subject};
r.Dump();
于 2013-10-01T21:19:45.810 に答える