Imtech Extended ContentQueryWebPart (with paging) source code available
Content Query Web Part, Development, SharePoint, Tools, WCMSome time ago I have created a concept of the ContentQueryWebPart extended with paging support, called Imtech Extended ContentQueryWebPart. Since its release, the Imtech ExCQWP has been downloaded more than 200 times and some of you have sent me some questions regarding how it all works.
One of the frequently asked questions was about sharing the source code of the web part. Because I'm curious of what other improvements could've been done, I have decided to post the source code and share it together with the .wsp.
The source code is available on CodePlex. Feel free to post any comments, suggestions and ideas of how the web part could be improved.

















December 12th, 2008 at 10:57 pm
Hi Waldek, I saw your post here about the CQWP: http://blog.mastykarz.nl/imtech-extended-contentquerywebpart-with-paging-source-code-available/
and thought if I can check with you on, how wld you achieve localization of the "custom web part properties" if the RESX file containing the localized strings are deployed to 12\Resources folders? Basically we are trying to avoid a satellite assembly for localization and keeping all our RESX entries in 12\Resources but not sure how to achieve the localization in this web part. Appreciate your valuable inputs.
December 13th, 2008 at 3:59 pm
It all depends where do you deploy the web part assembly. If it's GAC a satellite assembly is the only option I believe.
December 15th, 2008 at 6:52 pm
Thanks Waldek, but I am not making the resx file part of the satellite file, actually the resx file will be deployed to 12\Resources folder and then using the SPUtility.GetlocalizedString() method I can get the localized value. I was not sure how would I use it with the Extended CQWP, as in webparts derived form Sharepoint.Webparts.WebPart we can use the loadResource() method and override the behavior by using SPUtility.GetLocalizedString().
December 15th, 2008 at 6:54 pm
Also I had another query on, what if one of the field in the Pages library that I am querying in my ECQWP is a RICH TEXT Field (with Html tags). Will the query returned by the EQWP (as XML) have the html tags intact? Appreciate your consitent help to me.
thank you.
December 15th, 2008 at 11:08 pm
@MOSSBUDY: As far as I know the HTML is being escaped by default. You can suppress is by including the disableoutputescaping="yes" attribute in xsl:value-of
December 15th, 2008 at 11:10 pm
@MOSSBUDY: I've seen some sample usage @ the MSDN page: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.getlocalizedstring.aspx. Have you looked there?
December 16th, 2008 at 12:23 am
I did look at those samples already, just wanted to understand how we can use it in your implementation of ECQWP. After little digging I found I need to replace the STRINGS in the toolpart by the SPUtility.GetlocalizedString() and that should do it.
Thanks a lot Waldek, you have been very humble and prompt and helpful. thanks again.
December 16th, 2008 at 12:26 am
Hey Waldek, as you have the Paging implementation, I thought I can check with you if you have tried the AJAX type implementation with the ECQWP? As currently it is a complete post back, once the user clicks on the Page number. With AJAX type implementation it would be only that part of the page that will be refereshed. Thought of checking with you, if you had tried.
thanks.
December 16th, 2008 at 8:31 am
@MOSSBUDY: That would improve the user experience indeed. On the other hand: I've developed the CQWP paging for WCM solutions in particular. In such scenario JavaScript is an optional technology on which you cannot rely. Second of all using the approach based on query string parameters you are able to persist the state: you can send someone a link to the 4th page. Using AJAX approach that wouldn't be possible as the URL doesn't change.
December 17th, 2008 at 12:37 am
Thats a real nice explanation and a very valid point on the query string parameter. Thank you Waldek.
December 17th, 2008 at 5:35 pm
Hey Waldek, I wanted to request you for another suggestion/advice from you. Is there anyway to hide the ECQWP if the number of records returned by the Query is 0. We would not event like to display an empty chrome with just the web part title, basically that area would appear blank.
thank you.
December 17th, 2008 at 5:41 pm
@MOSSBUDY: When it comes to output it shouldn't be that difficult. You would most likely have to modify the ContentQueryMain.xsl as it's the entrance point of the XSLT transformation applied to the XML results.
As it comes to hiding the whole Web Part: I don't think it's doable in a manageable way. I mean, sure you could hack something together but is it really worth it? If it's really that important: why use the standard chrome? If you want to display the Web Part title you could extend the XSLT parameters and create your own title bar inside the XSLT which you could conditionally hide.
December 20th, 2008 at 9:37 pm
Hi There,
Thank you for your nice post.I just started working in MOSS.i don't know how to install the web part.can you please send some installation step so i can go ahead and install and play with it.
Thank You
December 21st, 2008 at 11:30 am
The Web Parts are provided in two forms: as SharePoint solution (WSP) and source code. To get the Web Part working on your site you have to first add the solution to your farm (stsadm -o addsolution), then deploy it to your Web Application using Central Administration > Operations > Solution Management and as last activate the Feature in your Site Collection using Site Actions > Site Settings > Site Collection Features. The Web Parts should become available and you should be able to put them on pages just as you would with any other Web Part.
December 22nd, 2008 at 6:50 pm
Thank You!!
December 23rd, 2008 at 5:42 am
Hey Waldek, another quick question I have a List with CUSTOM FOLDER content type and CUSTOM ITEM content type. Folder acts as a Parent and Items inside the Folder content type are child to the Folder. Folder also has some attributes and this list purely mimicks Parent-Child information as available here: http://cisa.ca/blogs/medhat/archive/2007/10/30/simulate-parent-child-relationship-in-sharepoint-2007-with-folders-amp-content-types.aspx. Now I have to use your ECQWP to get a result that looks like as follows:
Comp_ID:123(coming from Folder, this if Folder attrib)
Comp_Name: ACME Corporation (coming from Folder, this if Folder attrib)
Employee ID 111: Jane Doe Downtown (comes frm item)
Employee ID 222: James White Apt (comes frm item)
Company ID : 456
Company Name : Bogus Enterprises
Employee ID 333: Judy Black Main Street
Employee ID 444: Brandon Wiley Riverside
So is there a way to write a CAML query that would return the results as shown above (these 2 items are using different content types, although). Is it possible to do this within ECQWP?
thanks
December 23rd, 2008 at 8:32 am
I don't think you would be able to get results in such way in a straight-forward manner. I mean you could always use XSLT to hack it around, but I'm not sure it will be easy, unless each item _knows_ in which folder it's being stored?
December 23rd, 2008 at 3:57 pm
Thanks Waldek,
Wish you Happy Christmas and Happy Holidays!
December 23rd, 2008 at 5:35 pm
@mossbuddy: You're welcome! Same to you
December 23rd, 2008 at 8:19 pm
Hey Waldek, sorry to bother you again. Going back to the query of Parent-Child. If I store both the Parent element and Child element in the Pages Libaray (so no folder) but different content type, do you think I will be able to get the data and apply the XSL on that so that it looks like:
Company ID : 456
Company Name : Bogus Enterprises
SOME MORE DATA ABOUT THE COMPANY kind of SUMMARY etc.
Employee ID 333: Judy Black Main Street
Employee ID 444: Brandon Wiley Riverside
Employee ID 111: Hello Street
Employee ID 222: Buffalo Riverside
December 30th, 2008 at 9:07 am
@MOSSBUDY: There is no JOIN in CAML so you would have to find another way of retrieving the related items. Of course if you would get all the items you could achieve the grouped view just as you mentioned. You would retrieve the related nodes using XPath
May 3rd, 2009 at 10:14 pm
Hi,
I have just a problem with the pager web part which renders the page numbers vertically. how to get them horizontally?
May 3rd, 2009 at 11:12 pm
@debab ramzi: you can use CSS to get it displayed horizontally instead of vertically.
June 26th, 2009 at 12:18 pm
hai Waldek Mastykarz
i am ravi and am feel very happy after used ur Extended Content Query Web Part and Extended Content Query Web Part Pager. Both are working fine. But in Extended Content Query Web Part Pager shows page numbers in Vertically with bullet feilds. how can i change that numbers in Horizontally.
Plz help me
thanks and regaurds
Ravikumar.sanapala
June 27th, 2009 at 11:09 pm
@ravi: you should use CSS to get the job done. The easiest way to do that is to use:
li { display: inline; }
Please note that it's only the beginning and there are still some styling left specific to your scenario to get the job done.
July 12th, 2009 at 1:11 pm
Hello,
I create a webpart that herite from the extended and I defined the filter programmatically and when I add my webpart in a page layout, I create a page from this page layout the filter is not applied, I must do modify the webpart and set ok because the filter is on.
So if you can help me,
Thanks
July 13th, 2009 at 7:10 am
@chahine: how do you apply the filter? Could you post some code?
July 13th, 2009 at 11:11 am
hello,
this is my code:
{
this.FilterField1 = "Country";
this.FilterType1 = "string";
this.FilterOperator1 = FilterFieldQueryOperator.Eq;
if (myCondition)
this.FilterValue1 = "canada";
else
this.FilterValue1 = "usa";
this.Filter1ChainingOperator = FilterChainingOperator.Or;
}
Best regards.
July 13th, 2009 at 6:23 pm
@chahine: At what point are you applying that filter?
July 14th, 2009 at 10:13 am
I test it for the onLoad, Render, Prerender but always the same problem.
July 15th, 2009 at 6:15 pm
@chahine: Have you seen Andrew Connell's article on the subject (http://www.andrewconnell.com/blog/archive/2008/02/18/Subclassing-the-Content-Query-Web-Part-Adding-Dynamic-Filtering.aspx). The article contains step-by-step explanation and a code sample.
July 16th, 2009 at 10:09 am
Hi,
Some person post the same problem like me, and Andrew Connell\'s did not respond to them.
So I think there\'s no solution for this moment.
Thank you for your help.