コード例 #1
0
        /// <summary>
        /// This method gets the contacts that have the special DisplayName and property
        /// definitions in the special folder.
        /// </summary>
        private static List <Contact> GetContacts(Folder contactsFolder, String name,
                                                  params PropertyDefinition[] schemas)
        {
            if (contactsFolder == null)
            {
                return(null);
            }

            List <Contact> contacts = new List <Contact>();

            SearchFilter.SearchFilterCollection filters =
                new SearchFilter.SearchFilterCollection(LogicalOperator.And);

            if (!String.IsNullOrWhiteSpace(name))
            {
                SearchFilter searchFilter = new SearchFilter.ContainsSubstring(ContactSchema.DisplayName, name);
                filters.Add(searchFilter);
            }

            if (schemas != null)
            {
                foreach (PropertyDefinition schema in schemas)
                {
                    SearchFilter searchFilter = new SearchFilter.Exists(schema);
                    filters.Add(searchFilter);
                }
            }

            const Int32 pageSize    = 10;
            ItemView    itemView    = new ItemView(pageSize);
            PropertySet propertySet = new PropertySet(BasePropertySet.IdOnly, schemas);

            propertySet.Add(ContactSchema.DisplayName);
            itemView.PropertySet = propertySet;

            FindItemsResults <Item> findResults = null;

            do
            {
                findResults      = contactsFolder.FindItems(filters, itemView);
                itemView.Offset += pageSize;

                contacts.AddRange(findResults.Cast <Contact>());
            } while (findResults.MoreAvailable);


            return(contacts);
        }