views:

117

answers:

0

I need to look into all Contact type folders in an outlook mailbox (could be folders other than 'Contacts').I could not find an ItemProperty which would help me retrieve all Contact folders. So,to do this, I am retrieving all folders in a mailbox first and then want to compare the FolderType of each retrieved folder to FolderType.ContactFolder. How do I get the folder type of a Folder instance?

private static List<Resource> GetResource(string mailboxName, FolderType type)
        {
            var contactResources = new List<Resource>();
            NetworkCredential credential = new NetworkCredential("username", "password");
            WebdavSession session = new WebdavSession(credential);
            session.UserMailbox = "https://myserver/exchange/emailaddress";
            Resource resource = new Resource(session);
            Mailbox mailbox = resource.Mailbox;

            var propertyName = new[]{ItemProperty.IsFolder};

            var select = new Select(propertyName);
            var from = new From(mailbox.Root, Scope.Deep);
            var where = new Where();

            var condition = new Condition(ItemProperty.IsFolder, Operator.Equals, true);
            where.Add(condition);

            var sqlQuery = new SqlQuery(select, from, where);
            MultiStatus multiStatus = resource.Search(sqlQuery);
            var searchResult = new SearchResult(multiStatus, propertyName);
            SearchResultRecord[] allRecords = searchResult.Record;

            for (int i = 0; i < allRecords.Length; i++)
            {
                //folder URL
                string folderUrl = allRecords[i].Address;
                Console.WriteLine("folderUrl=" + folderUrl);
                Folder folder = resource.GetFolder(folderUrl);
             **// Here I want to compare the folder's type toFolderType.ContactFolder**  
               //And if the folder is of Contact type , add to contactResources 
            }


            return contactResources;
        }