Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We are having problems with our CQWPs when deploying our site to another environment. So the original issue was, the ListGuids are different on each environment so the CQWP throws an error after deployment.

So our solution was to edit each CQWB using a ps1 script (PowerShell) using the $web.GetLimitedWebPartManager() method.

Now the problem is, since the WebPart is has the wrong list guid, it is in an error state and therefore shows up as an ErrorWebPart in the WebPart collection.

So the questions are:

  • Is there any way to get the underlying web part from the ErrorWebPart and update it
  • Is there any other automated way for us to edit web parts in a page

its a catch22. We cant update the webpart until its fixed but we cant fix the web part if we cant update it.

Update:

Now we have found out that the errorweb parts are caused by custom xsl files that we use. The problem is better described here: http://vspug.com/koning53/2007/11/26/bug-in-contentbyquerywebpart-when-opened-in-a-non-web-context/

Now what I want to do is spoof the http context so I can retrieve the CQWP or if that's not possible, get the underlying webpart that has been substituted by the errorwebpart

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

I found to the solution to this problem. Well upon further research it seems like its not the list guid that's causing the cqwp to show up as an error web part. apparently its the custom xsl that we're using. The error is thrown when the web part tries to resolve the xsl template path using httpcontext.current (which is null in our case since it is not a standard web request). So I just spoofed the httpcontext and all went fine.

share|improve this answer
    
I am having the same issue with PowerShell. It works in the PowerShell ISE, but gives me an ErrorWebPart when run from a normal command prompt. How did you spoof the HttpContext? –  Kirk Liemohn Jul 9 '12 at 14:53
1  
Found someone that described a pretty complete solution: derde.net/blog/post/… –  Kirk Liemohn Jul 9 '12 at 18:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.