I'm creating a new ClientContext:

ClientContext clientContext = new ClientContext(targetUrl);

When trying to do a simple search:

KeywordQuery keywordQuery = new KeywordQuery(clientContext);
keywordQuery.QueryText = "test";
SearchExecutor searchExecutor = new SearchExecutor(clientContext);
var results = searchExecutor.ExecuteQuery(keywordQuery);

The results are returned, but only for the site from the targetUrl used in the context. Is there any way to return results across all sites using .Net CSOM Search?


I needed to add <AppPermissionRequest Scope=”http://sharepoint/search” Right=”QueryAsUserIgnoreAppPrincipal” /> to appmanifest.xml to query against the farm. Without setting this permissions, search will only return results from the site the app is installed on.


You could tweak the query text by introducing ContentClass managed property, to retrieve results across all the sites:

keywordQuery.QueryText = "contentclass=\"STS_Web\" AND contentclass=\"STS_Site\"";
  • 2
    Thank you for the answer, but, I might have misspoke. I'm not trying to get all sites, I'm trying to search across all sites
    – Adam
    Jun 27 '14 at 12:18
  • Sorry, I meant to search across all sites but I missed out on some words. See my updated response. The query will you results across all sites. Jun 27 '14 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.