Click here to Skip to main content
14,088,376 members
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 12 Jun 2007

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


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.


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


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 = "<a href="https://servername/_vti_bin/search.asmx">https://servername/_vti_bin/search.asmx</a>";
queryPeople.PreAuthenticate = true;
queryPeople.Credentials = new System.Net.NetworkCredential("userID", "<a>passwd</a>", "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();
                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("<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 + "%')");
                    query.Append(" AND (\"WORKPHONE\" LIKE '%" + phone + "%')");
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.


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

You may also be interested in...


Comments and Discussions

QuestionException - ERROR_SERVER Pin
Suhail Jamaldeen12-Oct-12 1:36
memberSuhail Jamaldeen12-Oct-12 1:36 
SuggestionSharepoint settings Pin
Member 94068774-Sep-12 22:50
memberMember 94068774-Sep-12 22:50 
Generalsearch result. Pin
sema z16-Feb-10 10:02
membersema z16-Feb-10 10:02 
Generalis there any way to bring everybody in AD Pin
sema z17-Jun-09 14:18
membersema z17-Jun-09 14:18 
AnswerRe: is there any way to bring everybody in AD Pin
gbelzile4-Nov-09 9:30
membergbelzile4-Nov-09 9:30 
GeneralGood info Pin
AnthonyKilhoffer3-Aug-07 4:58
memberAnthonyKilhoffer3-Aug-07 4:58 

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

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

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190518.1 | Last Updated 12 Jun 2007
Article Copyright 2007 by Vinay Yeluri
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid