Showing posts with label CQWP. Show all posts
Showing posts with label CQWP. Show all posts

Friday, June 1, 2012

Use Content Query WebPart with site definition

When you want to create site using custom site definition and want to use Content Query WebPart, Export definition of your web part from existing site. You will find list is defined by Id called ListGuid. But the ListGuid is never the same when you create a new List. You need to do the the following steps before adding exported web part to your onet.xml:
  1. Remove ListGuid
    <Property name="ListGuid" type="string"></Property>
  2.  Add ListName and WebUrl (if they are not exist)
    <Property name=”ListName” type=”string”>Posts</Property>
    <Property name=”WebUrl” type=”string”>~site/</Property>
Note:
  1. ~site represent current site. you can use ~sitecollection to represent current site collection.
  2. ~site/ I added slash because if we are in root WebUrl will be blank and CQWP will not be rendered.

Wednesday, December 29, 2010

Anonymous user access CQWP

When trying to access Content Query Web Part with anonymous user, It failed to render. While it is working correctly with anonymous user.

I’ve found out that we can fix this issue by adding two fields to the CommonViewFields property of the CQWP:

DocumentIconImageUrl and OnClickForWebRendering, like this:


<property name="CommonViewFields" type="string">DocumentIconImageUrl, Text;OnClickForWebRendering,Text </property>

Other work around:

Create WebPart inherit the CQWP and add an extra column to the resulting table containing data:


public class AnonWorkingContentByQueryWebPart : ContentByQueryWebPart
{
protected override void OnInit(EventArgs e)
{
this.ProcessDataDelegate = ProcessItems;
}

protected virtual DataTable ProcessItems(DataTable data)
{
DataColumn column = new DataColumn("OnClickForWebRendering", typeof(string));
data.Columns.Add(column);

return data;
}
}

I prefer first solution