HomeDevelopment (Old) Create a Content Query Webpart in Site Definition (onet.xml), with dynamic...

[SharePoint 2010 – Developpement] Create a Content Query Webpart in Site Definition (onet.xml), with dynamic site Url

I wanted to create a webtemplate with content query webpart in pages. Those webpart had to have the current site url. So I used the hack “~Site” in the properties of the webpart
Here are the step for it :

Step 1 : Create the Content query WebPArt Graphically

Create your webpart, and edit its properties (filter on content type, on column etc)

STEP 2:  Export the WebPart

From the page, export the webpart

STEP 3 : Modify the generated file exported .webpart

Modification 1 :
<property name=”ListGuid” type=”string”>d2d…
replace it by =>
<property name=”ListGuid” type=”string”/>

Modification 2 :
replace the property Weburl by
<property name=”WebUrl” type=”string”>~Site</property>

=> ~Site generates the website url dynamically

Step 4 : Integrate the CQWP in your onet.xml

In the AllUsersWebpart Tag, put the code of your webpart as that :
   1: <AllUsersWebPart
   2:           WebPartZoneID="Left"
   3:           WebPartOrder="1">
   4:           [CDATA[<webParts><webPart xmlns="http://schemas.microsoft.com/WebPart/v3%22>
   5:     <metaData>
   6:       <type name="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
   7:       <importErrorMessage>Cannot import this Web Part.importErrorMessage>
   8:     metaData>
   9:     <data>………..data>
  10:   webPart>
  11: webParts>]]>
  12:         AllUsersWebPart>

Deploy the solution and it will work Sourire

- Advertisement -

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

CONNECT FOR MORE CONTENT

DO NOT MISS THOSE ARTICLES

Recent Comments