SharePoint 2010: Why is my custom Content Query Web Parts not working on other site collections?

Scenario:

When we are working on the custom content query web parts, we always have our own xsl files, in order to apply these custom styles into our custom content query web parts, we need to change one-three of the properties to get it working, it would be

  1. HeaderXslLink
  2. MainXslLink
  3. ItemXslLink

So when you change the property of one of the following, let’s say ItemXslLink

<property name=”ItemXslLink” type=”string”>/Style Library/Xsl Style Sheets/CustomItemStyle.xsl</property>

It will works fine as long as that location/root site collection exist, but what happen is when you only deploy to a site collection which is not the root one, and the solutions didn’t get deploy to the root site collection?

In order to fix this issue:

  1. Modify the link to something like ~siteCollection/Style Library/Xsl Style Sheets/CustomItemStyle.xsl
  2. Add a event receiver for the feature activation
  3. Loop through all the custom web parts files and replace the “~siteCollection” hat with the current site ServerRelativeUrl

This will fix the web parts reference in some similar scenarios when you cannot import the web part

Advertisements

One thought on “SharePoint 2010: Why is my custom Content Query Web Parts not working on other site collections?

  1. Oh my goodness! Awesome article dude! Thanks, However I am experiencing issues with your RSS. I don’t understand why I can’t join it. Is there anybody else having identical RSS issues? Anyone that knows the solution can you kindly respond? Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s