Posted tagged ‘Presentation’

SharePoint Content Query WebPart (Customizable, Powerful, and Invaluable to ANYONE who uses SharePoint)

July 25, 2008

Out of the box SharePoint provides ANYONE with almost everything you could possibly need to present SharePoint data (list items, documents, you name it..) onto a webpage. Whether you have an intranet, extranet, and/or internet SharePoint deployment one of the single most important webparts will be the SharePoint Content Query WebPart.

Not sure what it is? Basically (very generalized description) it allows you to roll up SharePoint data into a customizable presentation. Read more here:

What this really means is two things:

  1. You can roll up pretty much any kind of “query” you can think of for SharePoint data. I could roll up all the policy documents throughout the entire site collection into one page for everyone to see, or maybe roll up the latest 5 news articles and present them to the viewer.
  2. You can CUSTOMIZE the look and feel VERY easily. This can allow some normal list data that looks like a listing of information to be INTERACTIVE for a user, or to look and feel exactly how you want it to!

The second point there is extremely important for those who are using it for internet sites. Want your news articles to roll up on your homepage and show just a thumbnail, title and description? Easy as pie! What if those news articles are all over the site, and are made by many different kinds of users? As long as you structured the data (used content types or something) you can just “Query” it with the content query webpart and voila it will appear.

Now for the part many people miss: But it doesn’t look the way I want it to, and all the options still don’t make it look the way I want.

No problem! If you have anyone who can do basic HTML you should be able to pull it off. (XSL skills are probably a good thing for anything more advanced than minor changes.)

The Content Query WebPart runs off of XSL!
Microsoft released wonderful documentation on how to modify it here:

But as always I will try and provide my own little example to help anyone who hasn’t caught on yet.

  1. Add a content query webpart to a page.
  2. Here is what mine looked like:
    Take a look at the drop down for item style, what I am going to take you through is how to make your own new item style, completely customizing the LOOK and FEEL for how my data items are displayed.
  3. Navigate to the site collection root and visit the StyleLibrary. Within this library is a folder called XSL Style Sheets. We are going to modify one of the files in here called ItemStyle.
  4. You can modify it in notepad, or in visual studio or some other XML/XSL editor. For this demo I will be using visual studio.
  5. Either write your own new template using the others as a guide OR copy one of them as a starting point. In this case we will just copy the “TitleOnly” template and paste it below.Notice that we change the NAME and MATCH of the template we copied. This is what it will show up in the drop down as, and how it will associate the styles and xsl you adjust in the actual content query webpart.
  6. Add some HTML or adjust the XSL as desired. In this sample I just added an image that will appear to the left of each title.
  7. Save and check the XSL change in.
  8. Open the content query webpart you added in step 1 and cause the item style drop down to display.

    You will notice our new template shows up.
  9. Click OK or Apply and VOILA – Customized Presentation (in my case an image of myself showing to the left of each item. Narcissistic I know.)

I hope you all see the power of this WebPart and use it to save you tons of time and effort,
Richard Harbridge

P.S – I highly recommend downloading and trying this solution on a development environment: which is basically a content query webpart enhanced with more properties pushed up to the user. It also has some other slick features, but basically makes the above steps far simpler to execute and adjust.

— UPDATE: This is a codeplex project, so there are some issues, specifically when dealing with non root site collections. I am advising this as something to start from 🙂 —