c# - 使用 C# 按日期列出 Outlook 中的约会

标签 c# outlook

我想使用 C# 按日期列出(提取)Outlook 约会。我使用限制方法来做到这一点,

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

但是,如果结束日期 (endDate) 之后的第二天有全天约会,它也会被列出。如何克服这个问题????

最佳答案

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; }
}

关于c# - 使用 C# 按日期列出 Outlook 中的约会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14251776/

相关文章:

c# - AutoMapper - 将源对象映射到嵌套对象

html - 电子邮件表格宽度在 Outlook 中中断

email - 在撰写模式下从邮件项中获取 SenderEmailAddress

展望 2013 : Adding button to reading pane?

excel - 如何复制带有签名图片的电子邮件正文

c# - 如何加载未净化的 XML?

c# - 在 C# 中计算 NxN 矩阵行列式

c# - MySQL选择结果保存到c#变量中

c# - 存储要在 Azure 角色之间共享的静态文件

excel - 通过 Outlook 电子邮件发送 Excel 形状