Showing posts with label Content Query Web Part. Show all posts
Showing posts with label Content Query Web Part. Show all posts

Thursday, 10 May 2012

SharePoint 2010 Console App returns ErrorWebParts


On a recent upgrade project I needed to update the properties of a Content Query Web Part. Sounds easy enough, just need to whip a quick console app and away we go.

Coding went very quickly, but when I ran the app I couldn't get any Content Query Web Parts, they were all returned as"ErrorWebParts".

I consulted my good friend google and found this blog post [1]. This guy was having the same issue as me and discovered that this web part references a SPContext object, unfortunately from a console app there is no web-context.

After reading this, I modified my code to set the HTTPContext.Current and like magic, I was able to edit the properties of all the CQWP.
[1] http://sharepoint-insight.blogspot.com/2008/10/sharepoint-all-webparts-appear-as.html

SharePoint Content Query Web Part not returning all results

On a recent SharePoint 2010 migration project we noticed that when we created new items (pages in the pages library), the Content Query Web Parts did not immediately display the results.



This seemed very odd at first, as I had never noticed a delay before with these web parts, so my first thought was a migration issue. But why would a migration only cause the web part to work slower.

So with the help of my good friend Google, I was able to find a blog post [1] that offered the following:CQWP ignores the following items:
  1. Items are check-out
  2. Items are not published and not-approved


But I was hitting publish on the page, so my items would not have fallen into either of these categories...unless it was just a delay in SharePoint marking the item as published.


Following the advice in the same blog post, I wrote a console app that targeted all the CQWP and changed the "UseCache" property to false.


Just like magic the items I created are now showing up immediately in their respective CQWPs.


Keep in mind this may not be the best solution for a site with a high load or CQWPs that are running large queries. You'll need to weigh the benefits of performance against immediate results. In most cases users will understand if there is a small delay as long as they have an understanding of the situation.


[1] http://msmvps.com/blogs/laflour/archive/2008/12/24/why-content-query-web-part-cqwp-doesn-t-return-all-results.aspx