none
EWS find contact folder in different mailboxes RRS feed

  • Question

  • Hi Pros,

    I tried to use the findItem Method of EWS 2010 to search for contact folders in other users mailbox.

    The user was given full access to the otherUsers mailbox.

    I expected the following code to give back the contact folders under otherUsers mailbox but there is no result given back.

             ExchangeServiceBinding esb = new ExchangeServiceBinding();
                esb.RequestServerVersionValue = new RequestServerVersion();
                esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010;
                esb.Credentials = new System.Net.NetworkCredential("myServiceUser", "pswrd", "myDomain"); 
                esb.Url = "https://myServer/ews/exchange.asmx";
                // Create the request and specify the travesal type.
                FindFolderType findFolderRequest = new FindFolderType();
                findFolderRequest.Traversal = FolderQueryTraversalType.Deep;
                // Define the properties that are returned in the response.
                FolderResponseShapeType responseShape = new FolderResponseShapeType();
                responseShape.BaseShape = DefaultShapeNamesType.AllProperties;
                findFolderRequest.FolderShape = responseShape;
                // Identify which folders to search.
                DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
                folderIDArray[0] = new DistinguishedFolderIdType();
                folderIDArray[0].Id = DistinguishedFolderIdNameType.contacts;
                
                folderIDArray[0].Mailbox = new EmailAddressType();
                folderIDArray[0].Mailbox.EmailAddress = "otherUser@mydomain.com"; 
            
                
                // Add the folders to search to the request.
                findFolderRequest.ParentFolderIds = folderIDArray;
                try
                {
                    // Send the request and get the response.
                    FindFolderResponseType findFolderResponse = esb.FindFolder(findFolderRequest);
                    // Get the response messages.
                    ews.ResponseMessageType[] rmta = findFolderResponse.ResponseMessages.Items;
                    foreach (ews.ResponseMessageType rmt in rmta)
                    {
                        // Cast to the correct response message type.
                        if (((ews.FindFolderResponseMessageType)rmt).ResponseClass == ResponseClassType.Success)
                            Console.WriteLine("Folder found");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

    I found some articles using a FindFolders() method which I can´t find in EWS 2010. Was it replaced by FindFolder()?

    Thanks in advance for your ideas!

    Tuesday, August 20, 2013 12:59 PM

Answers

  • Yep, have a look to FolderView and Folder.FindFolders method.

    Something like :

    FolderView fview = new FolderView(100);
    fview.Traversal = FolderTraversal.Deep;
    fview.PropertySet = PropertySet.FirstClassProperties;
    FindFoldersResults folders = null;
    Folder contactFolder = Folder.Bind(service,  WellknownFolderName.Contacts);
    
    folders = contactFolder.FindFolders(fview);
    Regards,

    Désiré GOVIN, Refresh IT Solutions.com

    • Marked as answer by Trombone Wednesday, August 21, 2013 11:31 AM
    Wednesday, August 21, 2013 7:52 AM

All replies

  • hi,

    you should use EWS Managed API (less code).

    However, after reading your code, for what you want to do (getting default contact folder), the correct method is GetFolder.

    Just for an example, your code with ews managed api looks like :

    ExchangeService service;
                service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                service.Credentials = new System.Net.NetworkCredential("login", "password");
                service.Url = new Uri("https://cas.mydomain.local/ews/exchange.asmx");
                FolderId principalContactFolderId = new FolderId(WellKnownFolderName.Contacts, new Mailbox("otherUser@mydomain.com"));
                Microsoft.Exchange.WebServices.Data.Folder contactFolder = Microsoft.Exchange.WebServices.Data.Folder.Bind(service, principalContactFolderId);


    Désiré GOVIN, Refresh IT Solutions.com

    Tuesday, August 20, 2013 1:39 PM
  • Hi,

    less code and works fine, thanks. Is there the possibility to enlinst all sub contact-folders under the contact folder by one ews request?

    Wednesday, August 21, 2013 7:38 AM
  • Yep, have a look to FolderView and Folder.FindFolders method.

    Something like :

    FolderView fview = new FolderView(100);
    fview.Traversal = FolderTraversal.Deep;
    fview.PropertySet = PropertySet.FirstClassProperties;
    FindFoldersResults folders = null;
    Folder contactFolder = Folder.Bind(service,  WellknownFolderName.Contacts);
    
    folders = contactFolder.FindFolders(fview);
    Regards,

    Désiré GOVIN, Refresh IT Solutions.com

    • Marked as answer by Trombone Wednesday, August 21, 2013 11:31 AM
    Wednesday, August 21, 2013 7:52 AM