Ews - Access All Shared Calendars

EWS - Access All Shared Calendars

By Shared Calendars do you mean the calendars under the other calendars node in Outlook ?

Other Calendars Node

If so these Items are NavLinks that are stored in the Common Views folder in a Mailbox which is under the NonIPMSubtree (root) see http://msdn.microsoft.com/en-us/library/ee157359(v=exchg.80).aspx. You can use EWS to get the NavLinks from a Mailbox and use the PidTagWlinkAddressBookEID extended property to get the X500 address of the Mailbox these Links refer to and then use Resolve Name to resolve that to a SMTP Address. Then all you need to do is Bind to that folder eg

     static Dictionary<string, Folder> GetSharedCalendarFolders(ExchangeService service, String mbMailboxname)
{
Dictionary<String, Folder> rtList = new System.Collections.Generic.Dictionary<string, Folder>();

FolderId rfRootFolderid = new FolderId(WellKnownFolderName.Root, mbMailboxname);
FolderView fvFolderView = new FolderView(1000);
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Common Views");
FindFoldersResults ffoldres = service.FindFolders(rfRootFolderid, sfSearchFilter, fvFolderView);
if (ffoldres.Folders.Count == 1)
{

PropertySet psPropset = new PropertySet(BasePropertySet.FirstClassProperties);
ExtendedPropertyDefinition PidTagWlinkAddressBookEID = new ExtendedPropertyDefinition(0x6854, MapiPropertyType.Binary);
ExtendedPropertyDefinition PidTagWlinkGroupName = new ExtendedPropertyDefinition(0x6851, MapiPropertyType.String);

psPropset.Add(PidTagWlinkAddressBookEID);
ItemView iv = new ItemView(1000);
iv.PropertySet = psPropset;
iv.Traversal = ItemTraversal.Associated;

SearchFilter cntSearch = new SearchFilter.IsEqualTo(PidTagWlinkGroupName, "Other Calendars");
// Can also find this using PidTagWlinkType = wblSharedFolder
FindItemsResults<Item> fiResults = ffoldres.Folders[0].FindItems(cntSearch, iv);
foreach (Item itItem in fiResults.Items)
{
try
{
object GroupName = null;
object WlinkAddressBookEID = null;

// This property will only be there in Outlook 2010 and beyond
//https://msdn.microsoft.com/en-us/library/ee220131(v=exchg.80).aspx#Appendix_A_30
if (itItem.TryGetProperty(PidTagWlinkAddressBookEID, out WlinkAddressBookEID))
{

byte[] ssStoreID = (byte[])WlinkAddressBookEID;
int leLegDnStart = 0;
// Can also extract the DN by getting the 28th(or 30th?) byte to the second to last byte
//https://msdn.microsoft.com/en-us/library/ee237564(v=exchg.80).aspx
//https://msdn.microsoft.com/en-us/library/hh354838(v=exchg.80).aspx
String lnLegDN = "";
for (int ssArraynum = (ssStoreID.Length - 2); ssArraynum != 0; ssArraynum--)
{
if (ssStoreID[ssArraynum] == 0)
{
leLegDnStart = ssArraynum;
lnLegDN = System.Text.ASCIIEncoding.ASCII.GetString(ssStoreID, leLegDnStart + 1, (ssStoreID.Length - (leLegDnStart + 2)));
ssArraynum = 1;
}
}
NameResolutionCollection ncCol = service.ResolveName(lnLegDN, ResolveNameSearchLocation.DirectoryOnly, false);
if (ncCol.Count > 0)
{

FolderId SharedCalendarId = new FolderId(WellKnownFolderName.Calendar, ncCol[0].Mailbox.Address);
Folder SharedCalendaFolder = Folder.Bind(service, SharedCalendarId);
rtList.Add(ncCol[0].Mailbox.Address, SharedCalendaFolder);

}

}
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}

}
}
return rtList;
}

Cheers
Glen

EWS - Access Shared Calendars

I got the answer. We have calendar call as below. service.FindFolders(new FolderId(WellKnownFolderName.Root, "email")

In this call we pass my email id. (My credential email).
If i need to access other user calendar(Shared calendar). I need to pass other user email address here. like service.FindFolders(new FolderId(WellKnownFolderName.Root, "Other user email").

Service object is created by my credential and just pass email of other user. Now you can get all calendar.

How do i access a shared calendar using EWS Managed API

You can just specify the calendar, which you want to acces in your FolderId.

FolderId folderIdFromCalendar = new FolderId(WellKnownFolderName.Calendar, "sharedInbox@example.com");

You can then use the folderIdFromCalendar for retrieving the calendar items, you want, e.g.:

FindItemsResults<Item> appointments = ExchangeServive.FindItems(folderIdFromCalendar, ItemView);

Remember that the program has to be run in the context of a user, which the mailbox is shared with.

Update:

If you happen to know the FolderId, you can just check, if the current user has access to this calendar by performing this code:

As above, you will need to initialize a FolderId:

FolderId folderIdFromCalendar = new FolderId("AQMkADAwATM3ZmYAZS1kNjE0LWU1ZmQtMDACLTAwCgAuAAADJRMtiupYBUGD‌​cKdcqUrr3AEA1/sqwbrw‌​UEeFM0Mc+UBFoQAAABzk‌​m1sAAAA=");

After that, try the following code:

if (folderIdFromCalendar != null)
{
try
{
ItemView cView = new ItemView(1000);
FindItemsResults<Item> appointments = service.FindItems(folderIdFromCalendar, cView);
int count = appointments.TotalCount; //just an example of some random action on the folder calendar
}
catch (ServiceResponseException ex)
{
Console.WriteLine("The specified calendar was not shared with you. \n" + ex);
}
}
else
{
Console.WriteLine("The specified calendar ID could not be linked to a calendar folder.");
}

Another Update:

if (folderIdFromCalendar != null)
{
if (folderIdFromCalendar.Mailbox.ToString().ToLower() == "your-Mailadress".ToLower())
{
Console.WriteLine("The folder you specified is your own");
}
else
{
try
{
ItemView cView = new ItemView(1000);
FindItemsResults<Item> appointments = service.FindItems(folderIdFromCalendar, cView);
int count = appointments.TotalCount; //just an example of some random action on the folder calendar
Console.WriteLine("You have been given access to this mailbox. Its owner is: " + folderIdFromCalendar.Mailbox.ToString()); //if you need to know, whos mailbox you are accessing right now
}
catch (ServiceResponseException ex)
{
Console.WriteLine("The specified calendar was not shared with you. \n" + ex);
}
}
}
else
{
Console.WriteLine("The specified calendar ID could not be linked to a calendar folder.");
}

Last Update:

I have googled quite a bit now and found something that worked for me. But to be perfectly honest, I don't understand everything, which is going on in the following code:

FolderId folderIdFromCalendar = new FolderId("AQMkADAwATM3ZmYAZS1kNjE0LWU1ZmQtMDACLTAwCgAuAAADJRMtiupYBUGD‌​cKdcqUrr3AEA1/sqwbrw‌​UEeFM0Mc+UBFoQAAABzk‌​m1sAAAA=");
Folder folderFromCalendar = Folder.Bind(service, folderIdFromCalendar);

AlternateId aiAlternateid = new AlternateId(IdFormat.EwsId, folderFromCalendar.Id.UniqueId, "random@mailadress.com");
AlternateIdBase aiResponse = service.ConvertId(aiAlternateid, IdFormat.EwsId);

var mailbox = ((AlternateId)aiResponse).Mailbox;

if (folderFromCalendar != null)
{
if (mailbox.ToString().ToLower() == "your-Mailadress".ToLower())
{
Console.WriteLine("The folder you specified is your own");
}
else
{
try
{
ItemView cView = new ItemView(1000);
FindItemsResults<Item> appointments = service.FindItems(folderIdFromCalendar, cView);
int count = appointments.TotalCount; //just an example of some random action on the folder calendar
Console.WriteLine("You have been given access to this mailbox. Its owner is: " + mailbox.ToString());
}
catch (ServiceResponseException ex)
{
Console.WriteLine("The specified calendar was not shared with you. \n" + ex);
}
}
}
else
{
Console.WriteLine("The specified calendar ID could not be linked to a calendar folder.");
}

I don't understand, how the string "random@mailadress.com" affects anything in that program, but the syntax needs a string there.

php-ews: Access shared calendars?

In the code block under Only look in the "calendars folder" add this in order to retrieve events from email@address.com's calendar:

$request->ParentFolderIds->DistinguishedFolderId->Mailbox = new StdClass;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = 'email@address.com';


Related Topics



Leave a reply



Submit