Microsoft Cloud Authors: Janakiram MSV, Yeshim Deniz, David H Deans, Andreas Grabner, Stackify Blog

Related Topics: Microsoft Cloud, Silverlight

Microsoft Cloud: Blog Feed Post

Query People Search in SharePoint Online

(and other SharePoint platforms too!)

At my Search talk at SPC11, I demoed how to build a Silverlight application that could query search in SharePoint Online.  I also built a separate application that could query people search, but I haven’t posted on it yet until today.  To query people search, we have to know a few things about how SharePoint operates.  It all starts with understanding the scopes involved.  If you take a look at your Search Scopes link in your site collection settings, you’ll see a similar list to the one below.


What’s funny here is that SPO actually returns item counts for the entire (non-partitioned index).  This tells me that there are 205,000 items and 96,000 people on my particular Office 365 SharePoint host.

Ultimately, querying people search is just a matter of executing a query against the scope People, but there are a few catches.  In SharePoint 2007, you could actually execute the query Scope:”People” on a results.aspx with a CoreResultsWebPart and you would actually get results.  It wouldn’t display pictures or additional user information such as department or phone number, but it would work.  With the introduction of federated search in SharePoint 2010, people search now gets executed by it’s own federated location named LocalPeopleSearchIndex (see my post on the QueryManager class for more information).  This means that a regular CoreResultsWebPart will not return results for Scope:”People” no matter what you do.


However, a PeopleCoreResultsWebPart will.


Issuing the query Scope:”People” will return every user in the user profile store.  Including service accounts like you see above.  The fact that I couldn’t issue a people search query to the regular CoreResultsWebPart actually threw me off for quite some time.  It just didn’t make sense to me what was going on behind the scenes.  It didn’t become ultimately clear, until I tried issuing the query to Search.asmx.  The Scope:”People” query works just fine when calling the web service.  Today you will learn how to query people search using the web service.  I’m going to use the exact same application I have been using with my other search demos, we’ll just tweak the input a little bit.

For today’s example, I am going to build off of the Silverlight 4 application I used at SPC.  I’m using Silverlight, but you could just as well write a console application or call this web service from some other ASP.NET application.  We still want to start by creating a service reference to /_vti_bin/search.asmx. We then create an instance of the web service so that we can use it.  We also bind an event handling method to handle the results of the web service call.

QueryServiceSoapClient queryService = new QueryServiceSoapClient();

queryService.QueryExCompleted += new EventHandler<QueryExCompletedEventArgs>(QueryService_QueryExCompleted);

Once we have a reference to the web service, it’s just a matter of constructing the input XML document and sending it to the web service.  For SharePoint Online and SharePoint 2010, we actually don’t have to change any of the XML at all. We just need to change the query. That means our input will look like the following.  Note, we’re using a type of STRING (even if using FAST Search for SharePoint).

<QueryPacket xmlns="urn:Microsoft.Search.Query" Revision="1000">

<Query domain="QDomain">





<QueryText language="en-US" type="STRING">Scope:"People"</QueryText>




If we are using FAST Search for SharePoint, we need to add to a ResultProvider element inside the Query element.  Remember, People Search is handled by the SharePoint 2010 search engine in FAST Search for SharePoint.





Just like before, I assemble this XML string using a StringBuilder.  I allow the user to type in a query and I just automatically append Scope:”People” to the query ensuring we only get people results.

StringBuilder queryXml = new StringBuilder();


queryXml.Append("<QueryPacket xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000\">");

queryXml.Append("<Query domain=\"QDomain\">");







queryXml.Append("<QueryText language=\"en-US\" type=\"STRING\">");

queryXml.AppendFormat("{0} Scope:\"People\"", SearchTextBox.Text);







We’ll then bind the resulting XML to a textbox so that we can look at the results.

ResultsTextBox.Text = e.Result.Nodes[1].ToString();

That’s all that is involved in this first round of code.  Compile the code and upload the Silverlight application to a document library and use the Silverlight web part just like before.  If you want more details on how the above code works, be sure and check out the original Search with Silverlight 4 post.   Let’s take a look at the results.  Here’s the application running.


I issues a query and I got results.  Let’s look at the XML in the results a bit more though.

<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">

<Results xmlns="">

<RelevantResults diffgr:id="RelevantResults1" msdata:rowOrder="0">



<Title>Craig Johnson</Title>






<HitHighlightedSummary />

<HitHighlightedProperties>&lt;HHTitle&gt;Craig Johnson&lt;/HHTitle&gt;&lt;HHUrl&gt;https://dotnetmafia-my.sharepoint.com/Person.aspx?accountname=i%3A0%23.f|membership|craig.johnson%40dotnetmafia.onmicrosoft.com&lt;/HHUrl&gt;</HitHighlightedProperties>



<PictureThumbnailURL>https://dotnetmafia-my.sharepoint.com/User Photos/Profile Pictures/[email protected]_MThumb.jpg</PictureThumbnailURL>


We have the user’s name in the Title field and we have some links to a picture and the user’s profile.  For the most part though, these fields aren’t entirely useful.  That’s because SharePoint treats this result as a regular document result instead of a person.  If we want useful information about the user, we have to ask for that information in our original query.  Specifically, we need to specify the names of the managed properties that we want returned (i.e.: JobTitle and Department).  How do we know what the names of those properties are?  In SharePoint 2010, we can just go look in the search service application.  However, we don’t have that option in SharePoint Online.  There’s another way though.  Go back to your PeopleResults.aspx page in your Search Center and edit it.  Then, you need to modify the PeopleCoreResultsWebPart.  Expand Display Properties and then uncheck Use Location Visualization.  The contents of the XML in Fetched Properties has the answer.


Here is what the XML looks like.


<Column Name="WorkId"/>

<Column Name="UserProfile_GUID"/>

<Column Name="AccountName"/>

<Column Name="PreferredName" HitHighLight="true"/>

<Column Name="YomiDisplayName" HitHighLight="true"/>

<Column Name="JobTitle" HitHighLight="true"/>

<Column Name="Department" HitHighLight="true"/>

<Column Name="WorkPhone" HitHighLight="true"/>

<Column Name="OfficeNumber" HitHighLight="true"/>

<Column Name="PictureURL"/>

<Column Name="HierarchyUrl"/>

<Column Name="WorkEmail" HitHighLight="true"/>

<Column Name="Path"/>

<Column Name="HitHighlightedSummary"/>

<Column Name="HitHighlightedProperties"/>

<Column Name="Responsibility" HitHighLight="true"/>

<Column Name="Skills" HitHighLight="true"/>

<Column Name="SipAddress" HitHighLight="true"/>

<Column Name="Schools" HitHighLight="true"/>

<Column Name="PastProjects" HitHighLight="true"/>

<Column Name="Interests" HitHighLight="true"/>

<Column Name="OrgNames" HitHighLight="true"/>

<Column Name="OrgUrls"/>

<Column Name="OrgParentNames" HitHighLight="true"/>

<Column Name="OrgParentUrls"/>

<Column Name="Memberships" HitHighLight="true"/>

<Column Name="AboutMe" HitHighLight="true"/>

<Column Name="BaseOfficeLocation" HitHighLight="true"/>

<Column Name="ServiceApplicationID"/>

<Column Name="SocialDistance"/>


This gives you quite a few choices to display in your results.  The column names are pretty self explanatory.  Now, we just have modify our input XML to specify which managed properties we want.  Do you remember how to specify managed properties with the Search web service?  If not, we start by adding a Properties element inside the Query element.  We then add a Property element for each managed property.  One thing to remember is that the managed properties must be specified in lower case.  You will get a NotFound exception if they are not.  Here is an example:


<Property name="accountname" />

<Property name="preferredname" />

<Property name="jobtitle" />

<Property name="department" />

<Property name="workphone" />

<Property name="officenumber" />

<Property name="pictureurl" />

<Property name="workemail" />


Remember, once you specify any column, you must specify every column you want.  The default columns will no longer be returned.  When we recompile, upload the new application, and execute a query again, we now get much better results.

<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">

<Results xmlns="">

<RelevantResults diffgr:id="RelevantResults1" msdata:rowOrder="0">

<accountname>i:0#.f|membership|[email protected]</accountname>

<preferredname>Craig Johnson</preferredname>


<department>Accounts Receivable</department>



<pictureurl>https://dotnetmafia-my.sharepoint.com/User Photos/Profile Pictures/[email protected]_MThumb.jpg</pictureurl>

<workemail>[email protected]</workemail>


You can query with these same managed properties as well.  For example, I could use the department managed property to see who is in Accounting with the following query.



Maybe, you want to look up who the CEO of the company is.  To do that use the jobtitle managed property.  Resist the urge to capitalize the words in the managed property.  They must be in lower case.  Note: that the title managed property is reserved for personal titles such as Jr., Sr. etc.



Now, that we can query with all of these properties, we can make a nice advanced people search application.  In my demo at SPC11, I used the Telerik RadGridView control to display the user information along with the picture from the user profile.  Here’s a screenshot of what the application looked like.


You can use the same techniques that I detailed in the Advanced Search with Silverlight 4 post to build a people search application like the one above.  This code will work on-premises (SharePoint 2010 or FAST Search for SharePoint) or in the cloud with SharePoint Online.  I’ve confirmed this works with both the P1 and E3 SKUs of Office 365.

Read the original blog entry...

More Stories By Corey Roth

Corey Roth, a SharePoint Server MVP, is a consultant at Hitachi Consulting specializing in SharePoint and Office 365 for clients in the energy sector. He has more than ten years of experience delivering solutions in the energy, travel, advertising and consumer electronics verticals.

Corey specializes in delivering ECM and search solutions to clients using SharePoint. Corey has always focused on rapid adoption of new Microsoft technologies including Visual Studio 2013, Office 365, and SharePoint.

He is a member of the .NET Mafia (www.dotnetmafia.com) where he blogs about the latest technology and SharePoint. He is dedicated to the community and speaks regularly at user groups and SharePoint Saturdays.

@ThingsExpo Stories
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics gr...