SharePoint Pals
 | Sign In
How to retrieve SharePoint List details by Content Query Webpart
by Tarun Kumar Chatterjee 26 Feb 2016
.Net – Technology Specialist
Today  :   6     Total  :    3329

Content search WebPart is used to fetch the data but it is fully depending on the Crawl. I mean to say, that the data will be available to the content search WebPart after crawl gets completed. In one of our requirement we had to fetch the data real time, so we decided to use Content Query WebPart.

Let see how we can fetch the data by using Content Query Webpart.

First let’s add 5 site columns named as EmpName, EmpEmail, EmpDept, EmpSalary & Emp Check

Create a list named as CQWebPartList

Add the 5 site columns to the newly created list & add few data into the list


Now create a SharePoint site page named as CQWebPartPage

Add a content query WebPart within the newly created page, Edit WebPart & add title as My Content Query.

Under query select the created list


Select the list type as below


Now export the content query WebPart

Create a sandbox solution

Add a module within the sandbox solution named as CQWebPartModule

Add the exported content query WebPart file under CQWebPartModule module

Go to the Style library -- > XSL Style Sheet

Download the default main & Item Style XSL files named as: ContentQueryMain & ItemStyle

Rename the downloaded XSL file as CQMain & CQItemStyle respectively. Add the files to the solution under a newly created folder named as “Style Library”

Now open Content Query.webpart which we have added already under the module and modify the below properties to link with the XSL files

<property name="ItemXslLink" type="string" >/sites/Site1/Style Library/XSL Style Sheets/CQItemStyle.xsl</property>

<property name="MainXslLink" type="string" >/sites/Site1/Style Library/XSL Style Sheets/CQMain.xsl</property>

Add the following field mapping

<property name="CommonViewFields" type="string" >Title, Text;EmpName, Text;EmpEmail, Text;EmpDept, Text;Emp_x0020_Check, Text;EmpSalary</property>

Replace Elements.xml by the below code snippet

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="">

<Module Name="CQWebPartModule" Url="_catalogs/wp">

<File Path="CQWebPartModule\My Content Query.webpart" Url="My Content Query.webpart" >

<Property Name="Group" Value="Custom" />




Now add the below template within CQItemStyle.xsl

 <xsl:template name="Employee-Details" match="Row[@Style='Employee-Details']" mode="itemstyle">
       <table width="100%" cellspacing="4" cellpadding ="4">
         <xsl:if test="count(preceding-sibling::*)=0">
             <td width="20%" valign="top">
             <td width="20%" valign="top">
               <b>Employee Name</b>
             <td width="20%" valign="top">
               <b>Employee Email</b>
             <td width="20%" valign="top">
               <b>Employee Department</b>
             <td width="10%" valign="top">
               <b>Employee Salary</b>
             <td width="10%" valign="top">
               <b>Employee Check</b>
           <td width="20%" valign="top">
             <xsl:value-of select="@Title" />
           <td width="20%" valign="top">
             <xsl:value-of select="@EmpName" />
           <td width="20%" valign="top">
             <xsl:value-of select="@EmpEmail" />
           <td width="20%" valign="top">
             <xsl:value-of select="@EmpDept" />
           <td width="10%" valign="top">
             <xsl:value-of select="@EmpSalary" />
           <td width="10%" valign="top">
             <xsl:value-of select="@Emp_x005F_x0020_Check" />

The field names in these are very sensitive and if we miss _x005f in the field name will break it. Make sure to include the correct field names, which is different from internal name.

Refer the below examples for various fields.

Field Name

XSL Field Name

Internal Name

Vendor Description






IT HelpDesk #



Use this in an itemstyle to output a header:

<xsl:if test="count(preceding-sibling::*)=0">

Use this in an itemstyle to output footer:

<xsl:if test="count(following-sibling::*)=0">

Add the below line of code in CQMain.xsl

<xsl:variable name="ItemStylePrefix" select="'Employee-'" />

Rebuild the sandbox solution and deploy

Under the Style Library add the two modified XSL files

Now from the Site Page delete the WebPart and add it again

Under presentation select the Item style “Employee-Details”


Save the WebPart & the output will be looking like


Hope this artifact will help the basic use & implementation of Content query WebPart.

Happy Coding

Tarun Kumar Chatterjee

blog comments powered by Disqus

SharePoint Pals

SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile


Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community

SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to in a word document.

Related Resources

Recent Tweets

Twitter October 23, 22:21
How to Add/Remove User Custom Actions (in Site Actions Menu) Programmatically using CSOM PNP in SharePoint -

Twitter October 21, 21:34
How to Add a JS Link Reference to the Display Form or Any other ASPX Programmatically using CSOM PNP in SharePoint -

Twitter October 20, 13:01
How to Add a JS Link Reference to the NewForm and EditForm Programmatically using CSOM PNP in SharePoint Office 365-

Twitter October 12, 12:15
How to Deploy Provider Hosted Apps (Add-Ins) by App Stapling in SharePoint Office 365 -

Twitter October 11, 13:39
How to Deploy Provider HostedApp programmatically using CSOM in SharePoint Office 365 Activating Developer Feature -

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation