2

How can retrieve only shared calendar using Exchange EWS API.

How can i know which calendar is shared using Exchange EWS API.

1
  • Firstly i call all my calendar by using below code FolderView fvFolderView = new FolderView(1000); fvFolderView.Traversal = FolderTraversal.Deep; SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.FolderClass, "IPF.Appointment"); FindFoldersResults ffoldres = service.FindFolders(new FolderId(WellKnownFolderName.Root, "email@address"), sfSearchFilter, fvFolderView); Now i get 3 calendar include one shared calendar. Need to Find shared calendar. Dec 12, 2016 at 10:17

1 Answer 1

5

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

FolderId folderIdFromCalendar = new FolderId(WellKnownFolderName.Calendar, "[email protected]");

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, "[email protected]");
    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 "[email protected]" affects anything in that program, but the syntax needs a string there.

9
  • I dont know the user email id for example het i don't know the email id "[email protected]" I am working in C# and try to know the shared calendar in my account. Dec 12, 2016 at 8:38
  • This will most likely not possible, as you have to give EWS some kind of information, where to retrieve the items from.
    – NotTelling
    Dec 12, 2016 at 8:41
  • So according to you, there is no way to find shared calendar in our account ? Dec 12, 2016 at 8:51
  • 1
    In my perception, EWS can't just print out a list of calendars, which are shared with a specific account. For all I know, you have to know, which calendar you want to access, before performing any actions in EWS. Do you use an exchange online server or are you hosting on-prem?
    – NotTelling
    Dec 12, 2016 at 8:59
  • I have calendar Id like AQMkADAwATM3ZmYAZS1kNjE0LWU1ZmQtMDACLTAwCgAuAAADJRMtiupYBUGDcKdcqUrr3AEA1/sqwbrwUEeFM0Mc+UBFoQAAABzkm1sAAAA= I want to know that this is shared calendar or not ? Dec 12, 2016 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.