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

lundi 27 juin 2011

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=">
   5:     <metaData>
   6:       <type name="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
   7:       <importErrorMessage>Cannot import this Web Part.importErrorMessage>
   8:     metaData>
   9:     <data>………>
  10:   webPart>
  11: webParts>]]>
  12:         AllUsersWebPart>

Deploy the solution and it will work Sourire

2 commentaires:

Anonyme a dit…

Thanks ;)

Anonyme a dit…

thanks ;)



Jeff ANGAMA, is a business / technique consultant around SharePoint 2013 technologies. - More Infos Here -

Rechercher dans ce blog

Follow by Email

Where Users are from ?