= ' " + startDate + " ' and [Start]-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:13:26 25 4
gpt4 key购买 nike

我想使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com