Rommel Sudan
Rommel Sudan

Reputation: 41

EWS Managed API: Cannot Retrieve Contacts, it always return 0

Good day.

I am using EWS Managed Api 2.0 to get the Exchange 2013 Contacts in my .NET 4.0 Application.

I have a working exchange server binding. here is my code.

FolderId foldid = new FolderId(WellKnownFolderName.Contacts);

                ContactsFolder contactfolder = ContactsFolder.Bind(exservice, foldid);
                ItemView view = new ItemView(500);
                view.PropertySet = new PropertySet(BasePropertySet.IdOnly);

                // Request the items in the Contacts folder that have the properties that you selected.
                FindItemsResults<Item> contactItems = exservice.FindItems(foldid, view);

                // Display the list of contacts. (Note that there can be a large number of contacts in the Contacts folder.)
                foreach (Item item in contactItems)
                {
                    if (item is Contact)
                    {
                        Contact contact = item as Contact;

                    }
                }

But When i run the code, the contactItems returns 0. This is strange because we have contacts in Exchange 2013. ( Itemcount = 0, TotalCount = 0)

EWS Managed API Contact is 0 Image

How do i solve this? I have posted this question into the Microsoft Tech Problem but no one replied yet.

Thank you very much.

Upvotes: 1

Views: 488

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

I would suggest you specify the Mailbox you want to access in the following line eg change

FolderId foldid = new FolderId(WellKnownFolderName.Contacts);

to

FolderId foldid = new FolderId(WellKnownFolderName.Contacts,"[email protected]");

Most likely what is happening is your not accessing the Mailbox your expecting to, you can also do some testing with the ewseditor https://ewseditor.codeplex.com/

Cheers Glen

Upvotes: 0

Related Questions