Custom Content Query Webpart View Additional/Custom Fields

Here I would like to explain details on How to fetch additional/custom fields in Custom Content Query webpart programmatically.

We can set CommonViewFields property of Custom Content Query webpart to fetch additional/Custom column.

Following is the example of sample Custom Content Query Webpart, I assume user has basic knowledge on how to create Custom Content Query webpart class. It is a normal class which Inherits from ContentByQueryWebPart

public class CustomCQWP : ContentByQueryWebPart
{

//Variable Declaration(same approach we take generally for class)

public string srtTBD;

Public int intTBD; etc.

// Override onInit method

protected override void OnInit(EventArgs e)
{

//here we write our sample query which will override existing ContentQueryWebPart’s Query.

base.OnInit(e);
SPQuery query = new SPQuery();

QueryOverride = “<Query><Where><Eq><FieldRef Name=\”Title\” /><Value        Type=\”Text\”>test</Value></Eq></Where></Query>”;

//here we specify additional/custom field which query should bring across

// this is similar to adding one more field to viewFields in CAML Query

QueryOverride = query.Query;
this.CommonViewFields = “PublishingPageContent,Publishing HTML”;

//this.CommonViewFields syntax would be “Internal Name, DataType”

}

protected override void CreateChildControls()

{ // Your code here..

}

}

————————————–

for queries, suggestions, feedback contact me on

email :bipinparshottam@gmail.com

skype: bipin.pankhania