page_type | products | languages | extensions | description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
|
Use the Search REST and OData endpoint, in a SharePoint Add-in, to programmatically search content are return the results. |
SharePoint add-in model is considered as a legacy option for extending SharePoint user interface. Please see SharePoint Framework documentation and the SharePoint Framework samples for the future proven option to extend SharePoint Online. Possible backend services should be using Azure Active Directly based registration and related app models.
Use the Search REST\OData endpoint, in a SharePoint Add-in, to programmatically search content are return the results.
- SharePoint Online and on-premise SharePoint 2013 and later
Scott Hillier, Critical Path Training
This sample requires the following:
-
A SharePoint 2013 (or later) development environment that is configured for add-in isolation. (A SharePoint Online Developer Site is automatically configured. For an on premise development environment, see Set up an on-premises development environment for SharePoint Add-ins )
-
Visual Studio and the Office Developer Tools for Visual Studio installed on your developer computer
-
Basic familiarity with RESTful web services
The sample accepts a query using the keyword query language (KQL) syntax as an input. It subsequently makes a call to the search engine using the SharePoint search REST\OData endpoint. The results are then displayed in a table, which is built dynamically using JQuery and JavaScript.
The code that uses the REST\OData endpoint for Search is located in the Add-in.js file of the project. The Default.aspx page of the add-in appears after you install and launch the add-in. When you enter a search term and press Search, the page looks similar to the following.
The sample demonstrates the following:
-
How to construct a REST\OData query to the Search endpoint.
-
How to parse the JSON-formatted data returned from the SharePoint and how to display it dynamically.
- Open Visual Studio as an administrator.
- Open the .sln file.
- In Solution Explorer, highlight the SharePoint add-in project and replace the Site URL property with the URL of your SharePoint developer site.
- Press F5.
- After the add-in installs, the consent page opens. Click Trust It.
- Enter a KQL query string in the text box beside the Search button and click the button. In a moment, the page refreshes and the returned data is displayed in a table.
Problem | Solution |
---|---|
Visual Studio does not open the browser after you press the F5 key. | Set the add-in for SharePoint project as the startup project. |
We'd love to get your feedback on this sample. You can send your questions and suggestions to us in the Issues section of this repository.
Get to know the SharePoint 2013 REST service.
OData: JavaScript Object Notation (JSON) Format
Copyright (c) Microsoft. All rights reserved.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.