Welcome to MSDN Blogs Sign in | Join | Help

How to Search On multiple Profile properties

The following is a sample code on how to search for multiple profile properties. Note that the Profiles Search handles only And operator when joining search clauses. 

            // Declare return variable.
            string returnValue = String.Empty;

            // Declare ProfileManagementContext.
            ProfileManagementContext profile;

            // Instantiate ProfileManagementContext as an instance of the
            // Profiles Web service.
            profile = ProfileManagementContext.Create("http://localhost/ProfilesWebService/ProfilesWebService.asmx");

            // Declare and instantiate SearchClause and SearchOptions objects.
            SearchClause searchClause = null;
            SearchClause rightClause = null;
            SearchOptions searchOptions = new SearchOptions();

            // Build dataset of searchable entities for a profile.
            DataSet searchableEntities = profile.GetSearchableEntities();

            // Build search clause for the UserObject.
            SearchClauseFactory factory = profile.GetSearchClauseFactory(searchableEntities, "Address");
            searchClause = factory.CreateClause(ExplicitComparisonOperator.Equal, "address_line1", "One Microsoft Way");
            rightClause = factory.CreateClause(ExplicitComparisonOperator.Equal, "address_line2", "One Microsoft Way");

            searchClause = factory.IntersectClauses(searchClause, rightClause);

            // Set number of records to return.
            searchOptions.NumberOfRecordsToReturn = 10;

            // Specify profile properties to return in the search dataset.
            searchOptions.PropertiesToReturn = "address_id, address_line1, address_line2";

            // Execute the search against the Profiles Web service.
            DataSet searchResults = profile.ExecuteSearch("Address", searchClause, searchOptions);

Published Tuesday, November 07, 2006 11:17 PM by Max Akbar
Filed under:

Comments

New Comments to this post are disabled
 
Page view tracker