Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Outlook C# VSTO, how can i get a reference to an appointmentItem given an EntryId, etc

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?

like image 469
leora Avatar asked Dec 29 '15 17:12

leora


1 Answers

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.

like image 67
Arturo Menchaca Avatar answered Nov 02 '22 15:11

Arturo Menchaca