Click here to Skip to main content
Click here to Skip to main content

People Search using search.asmx

, 12 Jun 2007
Rate this:
Please Sign up or sign in to vote.
Provides information on how to do a people search using search.asmx

Introduction

This article aims at providing the reader information on how to use the Sharepoint search webservice to do a people search and there by also attain a degree of wildcard search functionality.

Background

The reason for developing this code is to provide a customizable search interface which is completely dettached from the sharepoint UI. This was primarily done as a part of a mobile sharepoint project and this allowed us to reduce the data rate of the page.

Using the code

In this project, I have a class Search.cs which handles the building of the query and calling the web service. The class would then return the xml string with the query results to the caller who would transform it to the right format using xslt. The search.asmx which is the search web service that is exposed by sharepoint is present in the following directory

http://servername/_vti_bin/search.asmx.

Steps Involved

1. Create a web reference to the web service and name it something like PeopleSearch

2. Once you have the reference in the class use it like below:

PeopleSearch.QueryService queryPeople = new PeopleSearch.QueryService();
queryPeople.Url = "https://servername/_vti_bin/search.asmx";
queryPeople.PreAuthenticate = true;
queryPeople.Credentials = new System.Net.NetworkCredential("userID", "passwd", "domain");

3. Once you have the reference you can build the query which is as shown below, in my search
I'm mainly intereseted in the first,last names or phone and hence the query as shown below
StringBuilder query = new StringBuilder();
            try
            {
                query.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                query.Append("<QueryPacket xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000\">");
                query.Append("<Query domain=\"QDomain\">");
                query.Append("<SupportedFormats>");
                query.Append("<Format>urn:Microsoft.Search.Response.Document.Document</Format>");
                query.Append("</SupportedFormats>");
                query.Append("<Context>");
                query.Append("<QueryText language=\"en-US\" type=\"MSSQLFT\">");
                query.Append("SELECT ");
                query.Append("preferredname, ");
                query.Append("Department, ");
                query.Append("WorkPhone, ");
                query.Append("WorkEmail, ");
                query.Append("Path ");
                query.Append("FROM SCOPE() ");
                query.Append("WHERE ");
                query.Append("(\"DAV:contentclass\" = 'urn:content-class:SPSPeople') ");
                if ((fname.Length > 0 || lname.Length > 0) && phone.Length == 0)
                {
                    if ((fname.Length > 0) && (lname.Length > 0))
                    {
                        query.Append(" AND (\"FirstName\" LIKE '" + fname + "%') AND (\"LastName\" LIKE '" + lname + "%')");
                    }
                    else if ((fname.Length > 0) && (lname.Length == 0))
                    {
                        query.Append(" AND (\"FirstName\" LIKE '" + fname + "%')");
                    }
                    else if ((fname.Length == 0) && (lname.Length > 0))
                    {
                        query.Append(" AND (\"LastName\" LIKE '" + lname + "%')");
                    }
                }
                else
                {
                    query.Append(" AND (\"WORKPHONE\" LIKE '%" + phone + "%')");
                }
                query.Append("</QueryText>");
                query.Append("</Context>");
                query.Append("</Query>");
                query.Append("</QueryPacket>");
4. Once you have the query built you can call the Query method of the webservice which would execute the query and return the xml.
resultString = queryPeople.Query(queryString);

Use the appropriate xslt to transform your results, this allows you to do a wild card search.


						

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Vinay Yeluri
Web Developer
United States United States
Sr. .NET Developer
MS in ComputerScience
Old Dominion University

Comments and Discussions

 
QuestionException - ERROR_SERVER PinmemberSuhail Jamaldeen12-Oct-12 1:36 
SuggestionSharepoint settings PinmemberMember 94068774-Sep-12 22:50 
Generalsearch result. Pinmembersema z16-Feb-10 10:02 
Generalis there any way to bring everybody in AD Pinmembersema z17-Jun-09 14:18 
AnswerRe: is there any way to bring everybody in AD Pinmembergbelzile4-Nov-09 9:30 
Search for domain name.
GeneralGood info PinmemberAnthonyKilhoffer3-Aug-07 4:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 12 Jun 2007
Article Copyright 2007 by Vinay Yeluri
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid