6
votes

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?

2
Do you need to store the EntryID in a database and use it later? Or do you need it just in the duration of the session?Yacoub Massad
@YacoubMassad - I am storing the EntryId (but to be honest, I don't see how that would give a different answer to my question)leora
There are different types of EntryIDs, some of them can span different sessions and some of them can only span a single sessionYacoub Massad
You would use it like this Application.GetNamespace("MAPI").GetItemFromID(entryIDForAppointment, EntryIdForStore). The store is the mailbox that you are dealing with. If you have any folder in the mailbox, you can use folder.StoreID to get the entry id for the store.Yacoub Massad

2 Answers

2
votes

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.

-1
votes

You want to use the GetItemFromID method of the NameSpace object (intuitively, this can be accessed via the Application.Session property)

You will need the Store ID of the MAPI store from which you want to retrieve the item.