question

YevgenChepurko-5926 avatar image
0 Votes"
YevgenChepurko-5926 asked eugene-astafiev answered

How to distinguish outlook calendars in c# code ?

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 ????????????

}

office-outlook-itprooffice-vba-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @YevgenChepurko-5926 ,

Welcome to our forum!

Looks like your issue is more related to c# code, please kindly understand that the Outlook tag here we mainly focus on general issues about Outlook desktop client. In order to better solve your problem, we will add "office-vba-dev" tag.

Thanks for your understanding and hope your issue would be resolved soon.

0 Votes 0 ·

1 Answer

eugene-astafiev avatar image
0 Votes"
eugene-astafiev answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.