Question

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...
Était-ce utile?

La solution

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.

Autres conseils

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.

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.

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top