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

I'm looking for a way to embed a pre-configured Content Query Web Part into a master page. In short, I have a SharePoint:DelegateControl on the master page and I want to plug the web part into it by using a Feature. I'm open to other options, but this seems to make sense if it is possible.

At this point I have a .webpart file containing all of the configuration necessary for the content query to work. I configured it and exported it from a page to obtain the .webpart file. How do I go about specifying that the contents of this webpart be used as the control for the SharePoint:DelegateControl in my master page?

What I have tried so far:

  • I took the contents of the .webpart file and tried to hack it into what looks like an Elements.xml (by mapping the metaData/type element to a Control element and copying over the property elements), but it simply doesn't show up in the master page -- it was a long shot...
share|improve this question

4 Answers 4

up vote 1 down vote accepted

I think CQWP is possibly the wrong route as it doesn't work across site collections, only within a single site collection.

It sounds like you're better off looking at creating a custom Data Source, adding that into your web.config and replacing the existing navigation delegates using a feature. Much simpler in the long run. Without knowing more about your overall solution I would suggest not going the CQWP route.

share|improve this answer
    
Thanks for the information, @Steve. I ended up NOT using a CQWP after all, but instead just wrote custom a UserControl. Your suggestion is essentially what we are doing now. –  Zack Mar 27 '12 at 6:21

Where exactly do you want the webpart to show up? If you put it in the master page, it will show up everywhere.

Usually this is not what you want with controls like CQWP.

Your options also depend on how you provision your solution.

The recommended approach is to use module features and solutions for master pages, page layouts and pages.

If this is how you do it (you should! You might want to consider putting it in the page you are provisioning (eg. Welcome page, article page..) by putting it in the AllUsersWebpart section of your Module element.xml effectively pushing it to the webpart zone of your choice on the page.

The advantage to do it this way in contrast to features, is that if you handle it with features, by default the webpart will be inserted every time somebody activate the feature.

Delegate controls are nice for alot of things, but I never tried using them for inserting web parts, only for "normal" user controls or web controls.

share|improve this answer
    
I want to use the CQWP for navigation across the entire site (across site collections); I want to embed it in the header part of the master page, so that's where I dropped the DelegateControl. –  Zack Dec 4 '11 at 16:22
    
if this is some kind of navigation, you are probably better off experimenting with the menu controls and data sources. You can insert your web part as a regular control outside of a zone, but you might experience issues as the rendering is handled by ASP.NET rather than SharePoint safe mode parser (i have seen this when i used uint as property data type, where parser complained it was not CLR compliant -but could insert it in a normal web part zone without issues) –  Anders Rask Dec 4 '11 at 21:21

What I have done in a situation like this in past is created a custom web control and override the CreateChildControls method. In this method you would create instance of your WebPart and programmatically configure the the webpart to match it with your .webpart file and add web part to the Controls collection of your control.

Now that you have a control you can use replace the DelegateControl with you custom control using standard technique using FEATURE.

share|improve this answer

Basicaly this operation is done by web part provision, but as I understand you have a lot of pages. In this case provision configuration should contain defenitions for all pages. I think that you can try to add web part to a page, configure its content, open this page in SharePoint Designer and copy markup into your control.

share|improve this answer

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.