I have a outlook VSTO addin and I am able to retrieve a list of calendar appointments by using this code:
private Items GetAppointmentsInRange(Folder folder, DateTime startTime, DateTime endTime)
{
string filter = "[Start] >= '"
+ startTime.ToString("g")
+ "' AND [End] <= '"
+ endTime.ToString("g") + "'";
Debug.WriteLine(filter);
try
{
Items calItems = folder.Items;
calItems.IncludeRecurrences = true;
calItems.Sort("[Start]", Type.Missing);
Items restrictItems = calItems.Restrict(filter);
if (restrictItems.Count > 0)
{
return restrictItems;
}
else
{
return null;
}
}
catch
{
return null;
}
}
and I can loop through this appointmentitems and get the entryId which i am told is the unique identifier for that series.
I am now trying to figure out, given an EntryId, what is the right code to get a direct reference to the appointmentItem series (without having to do a search for everything and filter on the "client side"
Is this possible in outlook vsto?
If you want to gets items (MailItem
, FolderItem
, AppoinmentItem
, ...) by EntryID
, you need to use GetItemFromID()
, this method returns a Microsoft Outlook Item identified by the specified entry ID (if valid).
This function is available in NameSpace
objects, you can get it using Application.Session
property or app.GetNamespace("MAPI")
call:
var app = new Microsoft.Office.Interop.Outlook.Application();
...
var ns = app.Session; // or app.GetNamespace("MAPI");
var entryID = "<apppoinment entry id>";
var appoinment = ns.GetItemFromID(entryID) as AppointmentItem;
But it is recommended that provides the folder's Id:
var entryID = "<apppoinment entry id>";
var storeID = "<folder store id>";
var appoinment = ns.GetItemFromID(entryID, store) as AppointmentItem;
Be aware EntryID
may changes if you moved the item into another store.
Futhermore, Microsoft recommends that solutions should not depend on the EntryID
property to be unique unless items will not be moved, for example if you call Respond()
method with olMeetingAccepted
or olMeetingTentative
a new appointment item with different EntryID
is created and the original is removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With