How to distinguish outlook calendars in c# code ?

Yevgen Chepurko 1 Reputation point
2022-04-14T10:05:54.517+00:00

Hi.
When a person from one company shares their calendar to a person from another company, the shared calendar finally appears as a copy inside main calendar.
The same place where private calendars resign.
We need a way in c# code for outlook automation to distinguish such calendars.
Please see below c# code snipplet demonstrating the issue:

// use Microsoft.Office.Interop.Outlook.dll as ref to the project
using System;

using System.Runtime.InteropServices;

using Microsoft.Office.Interop.Outlook;

var outlookApp = new Microsoft.Office.Interop.Outlook.Application();

var ns = outlookApp.GetNamespace("MAPI");
var defaultCalendarFolder = ns.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
var foldersInsideDefaultFolder = defaultCalendarFolder.Folders;
for (int i = 1; i <= foldersInsideDefaultFolder.Count; i++)
{
MAPIFolder item = foldersInsideDefaultFolder[i];
Console.WriteLine($"Calendar: {item.Name}");

             // how can we distinguish a private calendar from a shared one here ????????????

}

Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
5,072 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Eugene Astafiev 891 Reputation points
    2022-04-17T10:40:51.353+00:00

    The Outlook object model doesn't provide anything for that out of the box. The only possible solution is to use the NameSpace.GetSharedDefaultFolder method which returns a Folder object that represents the specified default folder for the specified user. So, you may try to retrieve one and check whether it is yours.

    However, you may try using a low-level API on which Outlook is based on - Extended MAPI. You may try to check out permissions of the folder, see Update Folder Permissions using VBA for more information.

    0 comments No comments