I'm building a web service that will search SharePoint site collection for certain items via search service, and then pass results to a list and as the result, display them in my web service method.

The problem is, I have no idea how to connect to a search service through the code and use it there, also can't seem to find any information about how to do it.

  • In 2013 and 2016 you can use REST or CSOM. In 2010 you have to use the Query or QueryEx web services. Aug 1, 2017 at 20:39

1 Answer 1


This is what works for me in CSOM (C#) in a SharePoint online environment. The code sample below only returns the first result, even if the search result returns more than one item (naturally you can use LINQ as you please). You did not specify your working environment, but I would think that there is an equivalent method for on-premise C# code.

        var keywordQuery =
        new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(ctx);

        keywordQuery.QueryText = keyword;
        keywordQuery.RowLimit = 500;

        var searchExecutor =
        new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(ctx);

        var results = searchExecutor.ExecuteQuery(keywordQuery);


        var bytitle = results.Value.FirstOrDefault().ResultRows.Where(c => c["Title"].ToString() == keyword);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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