mandag den 8. februar 2010

Customize Content Query in SharePoint 2010

In SharePoint 2010, there is no need to define CommonViewFields in Content Query web part in order to display custom fields. As in SharePoint 2007, the Content Query web part in SharePoint 2010 is set to display items via XSL file ItemStyle.xsl.The new and very cool feature that comes with SharePoint 2010 is that Content Query web part detects the fields such as Title, Dsecription etc. that are defined in the XSL file and displays those fields in Tool Pane. Each field is displayed as a text box for you to enter the field name.

It's much easier to understand if you try it your self. Let's say that you have Customer content type that has a Title,Comments, and Products fields (columns).
Here is the example of how to display Title, Comments field as description, and a Products custom field.
0. Create Customer content type and a list with this content type
1. Add a Content Query web part to the page
2. Select the list and a Products content type
3. Change the name to Products in Appearance and click on OK button in the bottom
4. Click on the arrow in upper right corner of the web part's title and choose Export
5. Save the web part as Products.webpart to your desktop
6. Open the root of your site collection, click on View All Site Contents and open the Style Library
7. Open XSL Style Sheets folder
8. Select ItemStyle.xsl and click on Download a Copy in the ribbon
9. Save the ItemStyle.xsl file to your desktop
10. Open the Products.webpart file in Notepad
11. Locate the ItemXslLink property
12. Change it to


13. Save the changes
14. Open your site in browser or SharePoint Designer and open Site Assets library
15. Upload the ItemStyle.xsl file into this Library
16. Open the site in browser, edit the page
17. Click on Add a Web Part in web part zone and click on Upload a web part
18. Browse to Products.webpart and upload it
19. Click on Add a Web Part again and add the Products.webpart
20. Open the Tool Pane for Products web part and fold out the Presentation group.
21. Here you can see Link, Image, Title, and Description text boxes in Fields to display
22. Click on OK button and save the web part settings
23. Use SharePoint Designer to open the ItemStyle.xsl (in Site Assets library) and locate



24. Scroll down and you'll find



25. Open the Tool Pane for Products web part and write Comments in Description text box, and save the web part settings (click on OK button)
26. Open Site Assets library in SharePoint Designer and check out the ItemStyle.xsl file
27. Add @Products to the XSL like this:



28. Save and check in the ItemStyle.xsl
29. Refresh the page in browser and edit the Products web part
30. When you open Presentation group in Tool Pane, you'll see a new text box called Products
31. Write Products in the text box and click on OK button to save the web part settings

Other Things I Wrote (SharePoint 2013)
Script Editor and Embed Code
JavaScript - Add List with Columns
Adventures with Napa Apps in SharePoint 2013
Install SharePoint 2013 Public Beta with no Domain Controller
Metadata Driven Navigation
Geolocation