Friday, April 3, 2015

Deploy Advanced Search Box web part to SharePoint 2013 using module

We use Advanced Search Box to refine our search using keywords, managed properties and result types.This is very useful tool when the SharePoint environment contains a large amount of data.

image

There can be situations where you need to add this web part to custom web part pages programmatically. This task was very easy in SharePoint 2010 environments as this web part (AdvancedSearchBox.dwp) is available in web part gallery. Unfortunately this web part is no longer available in web part gallery in SharePoint 2013.

In this article I’ll show how to make that web part available in web part gallery so you can add it to pages later. Following are the steps I used to deploy the web part to the gallery

1. Navigate to the search center and execute sample query to get Advanced Search option

image

2. Edit the Advanced Search page and edit web part properties if required

image

3. After customizing properties, export the web part

image

4. Navigate to your visual studio solution and add a new Module. Include exported web part in that module

image

5. Modify Elements.xml as below

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  3.   <Module Name="WebParts" Url="_catalogs/wp" RootWebOnly="TRUE">
  4.     <File Path="WebParts\AdvancedSearchBox.dwp" Url="AdvancedSearchBox.dwp" Type="GhostableInLibrary">
  5.       <Property Name="Group" Value="Default Web Parts"></Property>
  6.     </File>
  7.   </Module>
  8. </Elements>

6. Deploy and activate the feature. Now the web part should be available in web part gallery

image

After the web part is deployed to the gallery we can easily add it to pages programmatically by using current page’s Limited Web Part Manager (SPWeb.GetLimitedWebPartManager)

No comments: