I need this meeting. If there is no current meeting, then the next or even previous meeting.
I suggest that you use Restrictit to limit the set of assignments, and then choose the first or last assignment depending on the restriction of the argument (for example, Limit assignments ending after the current time, or assignments should start before the current time).
I'm having problems with the string filter needed as an argument.
A simple example of VB (code cloning):
myStart = Format(Date, "mm/dd/yyyy hh:mm AMPM")
strRestriction = "[Start] <= '" & myStart & "'"
'Restrict the Items collection
Set oResItems = oItems.Restrict(strRestriction)
'Sort
oResItems.Sort "[Start]"
I am trying to do the same in C #.
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
oNS.Logon(Missing.Value, Missing.Value, true, true);
Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
oItems = oCalendar.Items;
oItems.IncludeRecurrences = true;
String filter = "[Start] <= '" + DateTime.Now.ToString("MM/dd/yyyy hh:mm AMPM") + "'";
Outlook.Items restrictedItems = oItems.Restrict(filter);
restrictedItems.Sort("[Start]");
Outlook.AppointmentItem oAppt = restrictedItems.GetLast();
oNS.Logoff();
I assume that since the filter is a string, the date format should be yyyy / mm / dd HH: mm: ss? I can’t find the documentation on how to manipulate [Start], for example, parse it for a date or something else.
, GetLast - , .
, ( ), , , (, https://social.msdn.microsoft.com//vstudio/en-US/c6a8bd21-6534-43be-b23e-1068651da92e/retrieve-meeting-items-from-outlook-2007-calendar-restrict? Forum = vsto, , , , , DateTime.Now.)
UPDATE: , . ?
DateTime currentTime = DateTime.Now;
foreach (Outlook.AppointmentItem item in oItems)
{
if (item.Start <= currentTime && item.End.Subtract(new TimeSpan(0, 10, 0)) > currentTime)
{
appointmentArrayList.Add(item);
}
}