Friday, June 1, 2012

Use Content Query WebPart with site definition

When you want to create site using custom site definition and want to use Content Query WebPart, Export definition of your web part from existing site. You will find list is defined by Id called ListGuid. But the ListGuid is never the same when you create a new List. You need to do the the following steps before adding exported web part to your onet.xml:
  1. Remove ListGuid
    <Property name="ListGuid" type="string"></Property>
  2.  Add ListName and WebUrl (if they are not exist)
    <Property name=”ListName” type=”string”>Posts</Property>
    <Property name=”WebUrl” type=”string”>~site/</Property>
Note:
  1. ~site represent current site. you can use ~sitecollection to represent current site collection.
  2. ~site/ I added slash because if we are in root WebUrl will be blank and CQWP will not be rendered.

No comments: