ContentBySearchWebPart class

The ContentBySearchWebPart is a Web Part introduced in SharePoint Server 2013 that can display dynamic content that was previously crawled and added to the search index.

Each Web Part instance is associated with a search query and shows the results for that particular search query. When users browse to a page that contains a ContentBySearchWebPart, the search query is automatically issued and the corresponding search results are returned from the search index.

You can use display templates, which are snippets of HTML and JavaScript, to change how search results appear on the page. Display templates render information returned by SharePoint; the information is inserted into the page in JSON format.

Inheritance hierarchy

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.Panel
        System.Web.UI.WebControls.WebParts.Part
          System.Web.UI.WebControls.WebParts.WebPart
            Microsoft.SharePoint.WebPartPages.WebPart
              Microsoft.Office.Server.Search.WebControls.ScriptWebPart
                Microsoft.Office.Server.Search.WebControls.DisplayScriptWebPart
                  Microsoft.Office.Server.Search.WebControls.ResultScriptWebPart
                    Microsoft.Office.Server.Search.WebControls.ContentBySearchWebPart
                      

Namespace:  Microsoft.Office.Server.Search.WebControls
Assembly:  Microsoft.Office.Server.Search (in Microsoft.Office.Server.Search.dll)

Syntax

'Declaration
<ScriptDescriptorComponentTypeAttribute("Srch.ContentBySearch")> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public Class ContentBySearchWebPart _
    Inherits ResultScriptWebPart
'Usage
Dim instance As ContentBySearchWebPart
[ScriptDescriptorComponentTypeAttribute("Srch.ContentBySearch")]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class ContentBySearchWebPart : ResultScriptWebPart

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also

Reference

ContentBySearchWebPart members

Microsoft.Office.Server.Search.WebControls namespace

Other resources

User segmentation in SharePoint 2013

Inheritance hierarchy

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.Panel
        System.Web.UI.WebControls.WebParts.Part
          System.Web.UI.WebControls.WebParts.WebPart
            Microsoft.SharePoint.WebPartPages.WebPart
              Microsoft.Office.Server.Search.WebControls.ScriptWebPart
                Microsoft.Office.Server.Search.WebControls.DisplayScriptWebPart
                  Microsoft.Office.Server.Search.WebControls.ResultScriptWebPart
                    Microsoft.Office.Server.Search.WebControls.ContentBySearchWebPart
                      Microsoft.Office.Server.Search.WebControls.CatalogItemReuseWebPart