简体   繁体   中英

How to use Exchange Web Services to find calendar items for other users

I'd like to write some code to query an Exchange Server to find calendar entries for a set of users. Is this possible?

I am new to using EWS. I'm finding it difficult to find any good overview documentation to guide me through how it should be used.

Anyway, the code I am trying is so far like this :

                    DateTime startDate = new DateTime(2015, 8, 1);
                    DateTime endDate = new DateTime(2015, 11, 1);
                    CalendarView calView = new CalendarView(startDate, endDate);

                    Mailbox mb = new Mailbox(@"somebodyelse@corp.testcompany.com");

                    FolderId fid = new FolderId(WellKnownFolderName.Calendar, mb);

                    FindItemsResults<Item> instanceResults = service.FindItems(fid, calView);

This last line throws a ServiceResponseException : "The specified folder could not be found in the store."

Is the above approach somewhere close to correct? Maybe there's a completely different and better way to do this anyway?

Note that my service object above is an ExchangeService object which I set up with credentials for administrator@corp.testcompany.com. I hope that the admin user has permissions to see the other users' Calendars, but maybe this also has to be setup explitly somewhere in Exchange?

Your code is fine. The error your are getting is probably related to access rights to the target mailbox. By default, the administrator does not get access to other user mailboxes.

To enable a user to access another user's mailbox, you can use powershell or the exchange management console:

Via powershell:

open the exchange management shell and run the following command:

Add-MailboxPermission -Identity "User1" -User "User2" -AccessRights FullAccess -InheritanceType All

This will give User2 access to User1's mailbox.

Take a look at this for more details.

Via exchange management console:

Open exchange management console, the go to recipient configuration -> Mailbox, and then select the target user. Right click on the user and click Manage Full Access Permission.

From there, add the user that you want to access the mailbox and then click "Manage".

Please note that this is based on Exchange 2010. On different exchange versions, this might be different. The powershell command I guess would be the same, but the GUI based configuration might be different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM