Customizing the Content Query Web Part and Custom Item Styles

With Microsoft Office SharePoint Server (MOSS) 2007 and Windows SharePoint Services (WSS) 3.0, we can use the
Content Query Web Part (CQW or CQWP) to display SharePoint content from another source on a SharePoint page.
This web part is rather nifty and one of my new favorite things about MOSS 2007.
At first glance you tend to pass it by, then when you see what it can do, it is
pretty cool.  Imagine if you will, creating a list in SharePoint 2003 and
then adding it as a web part to your WSS home page or SPS portal area.  You
are then limited to controlling the view through the Web Part Tool Pane by
hiding or showing various columns.   With the CQWP, you can now
control how that content is displayed. You can wrap HTML code and styles to
format the display nearly however you wish.  Here is a quick example of a CQWP
used on the ShareSquared.com site:

Sample CQWP

The data that is used here is stored in a Pages library for a News site, which of course is just
a list. Through Item Styles used by the CQWP, I can control the
display of the data nearly any way I wish.

Creating the Custom Item Style

First, hands down this is a fantastic blog post to read on the subject:

Configuring and Customizing the Content Query Web Part
on the
ECM Blog.   That
post is what I followed to create custom Item Styles.  This article is just
to help fill in the blanks on how to use this process for your own site.

I am going to breeze through some of the steps that are documented on the ECM
blog, and go into others in more detail that are not documented in that post.

Add a CQWP To The Site

  1. Add a Content Query Web Part to a page in the site. By
    default the CQWP will display all of the pages in the site.
  2. Now choose to Modify the Shared Web Part and in the
    Web Part Tool Pane, expand Query and
    change the Source
    settings to the site or list where you want to query the data from.Query settings in the Tool Pane
  3. Optionally update other settings to further refine the data view, such
    as Content Type and Filters. Select Apply.
  4. For more details, look and Steps 1 and 2 in the

    Configuring and Customizing the Content Query Web Part
    post.

Create the Custom Item Style

Now we have a rather boring view of some data. We use Item Styles
to jazz up the formatting and selectively show various content, such as
Title, Description and Body.  There are already several Item Styles
available out-of-the-box, but in my opinion, they have limited use. Go ahead and
play around with what is available, there maybe something there that is perfect
for your needs and it helps you to see what you can do with an Item Style.
In the Tool Pane, expand Presentation and experiment with the
drop down options under Styles. Select Apply
to see the changes.

Before we style any content, we need to have the web part pull in the content we want
to display. Some
content is already pulled in by default, such as Title.  For anything else that is not
pulled by default, we need to tell the web part to get those fields. But how do
we know which fields are already being pulled in?  It is a bit of a chicken
and the egg ordeal, so here are my suggested steps for working all of this
information out:

Heads up!  Here is where we deviate from the

Configuring and Customizing the Content Query Web Part

post.

  1. Open the site in SharePoint Designer (SPD). Navigate
    to Style Library, then XSL Style Sheets.
    Open ITEMSTYLE.XSL.  Now doing this will customize (uhghost)
    the file! But we can always reset this back to the Site Definition and
    restore it to it’s original state.  Be sure to check out the file via
    SPD or the Site Content and Structure screen in the site.
  2. Take a minute to look at the file.  Every time you see “<xsl:template…”
    that is the start of a new Item Style.  There is one for each of
    the out-of-the-box Item Styles that show up in the Styles drop down in the
    Web Part Tool Pane.  For every custom Item Style that is needed, a new
    xsl:template block will have to be created.
  3. Scroll down to the bottom of the file. Copy the last
    xsl:template
    code block and paste it above the closing xsl:stylesheet
    tag.
  4. Change the name and match properties
    in the Templatetag to a unique name of your choice:<xsl:template name=”MyCustomStyle” match=”Row[@Style=’MyCustomStyle‘]”
    mode=”itemstyle”>
  5. Next we will add a little snippet of code within the Template tags that
    will render the names of the fields that are being passed.  Note that
    this code will be temporary! We don’t want to leave this in the finished
    Item Style.<xsl:template name=”MyCustomStyle” match=”Row[@Style=’MyCustomStyle’]”
    mode=”itemstyle”>
    <xsl:for-each select=”@*”>
    P:<xsl:value-of select=”name()” />
    </xsl:for-each>
  6. Save the file.  Return to the site (in the browser) and refresh
    the page.  Open the Web Part Tool Pane for the CQWP and expand
    Presentation
    , then under Styles change the
    Item Style
    to the new custom style in the drop down.  Select
    Apply.
  7. The CQWP will now list out all of the fields that are being passed.CQWP Passed Fields

    After each P: is the internal column name for each field
    that is being passed.  These internal column names are what is
    referenced later in the code to display the data.  For example:

    <div class=”description”>
    <xsl:value-of select=”@Description” />
    </div>

    Description is the internal column name that is being
    wrapped and styled with a DIV tag and is the content that will display on
    the page.  So we can look at the names displayed in the CQWP and see
    what data is already available for our use.  For example, in this
    particular case we have Title, Author, Publishing Rollup Image and
    Publishing Date (PubDate).

Find the Additional Data

Our first goal was to determine what content is already being pulled into the
web part.  Now that we have done that, next we need to tell the web
part to pull the other data we need. To do this we will need to get the internal
column names for the necessary column(s) from the Content Type that is being
used for the list.

  1. In the site, open Site Settings, then select
    Site Content Types
    .  Locate the Content Type that the list is
    using.  For example:

    • If you are querying a site and showing pages, look under Page Layout
      Content Types.
    • If you are querying a list, look under List Content Types.
  2. Select the Content Type name to view the Columns. Locate the column that
    needs to display in the custom item style. Locate the internal column
    name one of two ways:

    1. Way One: Click the column name.  In the Change Site Content Type
      Column
      screen, hover over the Edit site column in new
      window
      link and note the URL that appears in the Status Bar.
      The internal column name appears after Field=. It also
      appears on the Site Content Type screen we just came from in
      the Status Bar, it is just inline with a lot of other characters. Often
      the string is too long in the Status Bar to display the Field property.Internal column name
    2. Way Two: Right click the link and
      select Properties.Content Type Columns

      The URL listed in the General tab has the info we need,
      just hidden below the viewable area.  Select the URL with your cursor,
      hit Ctrl + A to select the full URL, the copy and paste the
      URL into Notepad.

      Copy the URL

      In the pasted URL in Notepad, locate Field=.
      The name that follows in the internal column name.

      Internal Column Name

Now that we have our internal column name, we can return to the
instructions in the

Configuring and Customizing the Content Query Web Part

post and proceed with their Step 3.

Modify the CQWP to Include Additional Data

  1. In your site, in the CQWP, select Export from the web part’s Edit menu.
    Save the .WEBPART file locally.
  2. Open the .WEBPART file in Notepad and search for “CommonViewFields“.
    Replace the Property tag line of code with the code listed below, using your internal column
    name and the corresponding field type. It is very
    important that the field type listed is the correct type for the the data.
    If the field type is wrong, it won’t break the site, but the Item Style
    won’t display the content. Available values are:

      • Text
      • Note
      • Number
      • Currency
      • Integer
      • Boolean
      • DateTime
      • Threading
      • Lookup
      • Choice
      • URL
      • Counter
      • DisplayOnly (DisplayOnly field type has no storage of its own)

    And I have either used or seen these used, but have not seen them documented anywhere:

    • RichHTML
    • Image

    Some field types are easy to figure out.  If we are calling a date, use
    DateTime. For Title use Text, for body content use
    RichHTML
    .
    String together multiple entries with a semicolon between each pair: Name, RichHTML; Name2, Text.

    <property name=”CommonViewFields” type=”string”>InternalColumnNameGoesHere,
    FieldType</property>

    For example: <property name=”CommonViewFields” type=”string”>Comments,
    Note</property>

    At the end of this article I cover how to find out the field type.

  3. Save the file and import it back into the site. (Add a Web Part
    Import – select the .WEBPART file – Upload
    – Drag and drop the web part onto the page).

Now we have two CQWPs on the page.  We can remove the original
one. We should also see the newly added internal column name(s) appear in the
list of fields.  Yay!!  18 steps later and now we are ready to style!!
No, really, this process moves pretty fast.  Now it is time to return to
the XSL file and start making things pretty.

Style the Data in the Item Style

  1. Return to SharePoint Designer and your custom template in ITEMSTYLE.XSL.
  2. For every internal column name that has been included in the web part and
    needs to display in the Item Style, add it to the template using the
    xsl:value
    tag:<xsl:value-of select=”@InternalColumnNameGoesHere” />

    For example: <xsl:value-of select=”@Comments” />

  3. Wrap HTML around the tag to format the data. 
    Please note!!
    When
    the page renders the CQWP, the site grabs the Item Style for each line of
    data.  So we can’t add a table and expect that each line of data will
    be in a row.  Instead we get a full table for each line of data.
    Keep this in mind as you style the HTML around the data.
  4. Save the file, go to the site and refresh the page.  The new styled
    content will appear.
  5. To remove markup tags, please refer to about the middle of Step 4 in the

    Configuring and Customizing the Content Query Web Part
    post.
  6. When done styling the Item Style, remove the code that lists the fields.

    <xsl:for-each select=”@*”>
    P:<xsl:value-of select=”name()” />
    </xsl:for-each>

The Other Internal Column Names & Finding Field Types

If by some odd reason you were following along with this article and trying
to do a CQWP Item Style on an events list, like I was, at the end of this you
were probably scratching your head as to why no content would display on your
site.  While writing this article I discovered that the internal column
name listed in the Content Type isn’t necessary the internal content name that
should be used for Item Styles.  I am sure I will make some developer have
a heart attack with my terminology or what have you, but after a lot of
searching I tracked down the real internal column names in the SCHEMA.XML file
for each feature (every list type is a Feature). Once I pulled the right
internal column name in my .WEBPART file and in ITEMSTYLE.XSL, things worked
like a charm.  Consequently, SCHEMA.XML also lists out the field types for
each column.

  1. On the web server, open the SCHEMA.XML file for the Feature. The
    Features are located in the Feature directory:
    Local Drive:Program FilesCommon FilesMicrosoft Sharedweb server
    extensions12TEMPLATEFEATURES(Feature Name)
  2. Locate the SCHEMA.XML file.  It will be in one of the two
    subdirectories in the Feature.  Open the file in Notepad.
  3. Locate the FIELDS element.  Within Fields are all of the FIELD
    elements used in the Feature.  Each one lists the column Type (field
    type) and Name (internal column name).Schema file
  4. Use this column type and name in the .WEBPART file and in the
    ITEMSTYLE.XSL file.

To wrap up my commentary with the Events list, I changed “Comments” to “Description” and the CQWP
successfully displayed the content in the CQWP.

Custom Item Style Samples

Here are some samples you can check out to see how it all comes together:

Code: Download
Screenshot: Sample Item Style
Code: Download
Screenshot: Sample Item Style

150 thoughts on “Customizing the Content Query Web Part and Custom Item Styles”

  1. Do you know how to get a Multiple Lookup column through the ItemStyle.xsl? I have tried using the “Lookup” field type, the “LookupMulti” field type and the “MultiChoice” field type, but nothing ever comes through.Thanks for any assistance.Duncan

  2. Hii,I am developing an application in which i have created around 30 form libraries but for the end users i dont want to show these libraries. I just want to show them all the documents present in those form libraries depending upon the item level permission.To achieve this i am implementing content query webpart and everything goes fine, but the problem is that i want to create UI of the content query webpart same as of my form library, i mean to say there should be colum headers with sorting and filtering functionality in the webpart for different fields present in the form library.I will appreciate any kind of comments or help on this problems.Thanks in advance.Prashant.

  3. Hi Heather,do you know if it is possible to filter a CQWP by using the “Current User Filter” web part. So make a connection between a CQWP and a filter web part?Thnx!Dirk

  4. Hello Heather-I have a question similar to Dirk’s question. I am attempting to connect a BDC List WP to a CQWP so that when I choose an item in my BDC List WP, it passes this to the CQWP which retrieves only those documents associated with that chosen BDC item – a reference to which is stored in a custom column in the document library I have my CQWP pointing to. I know this sort of connectivity already exists between a BDC List WP and the BDC Data Item and BDC Related List web parts, so I was thinking that it might already possible somehow by properly configuring the out-of-the-box web parts. Any thoughts you might have on this would be greatly appreciated. Thanks in advance.

  5. Hi Heather.I am new to sharepoint. Is CQWP really available in WSS 3.0? I can’t find it anywhere… The closest thing I can find is the Content Editor Webpart. Thanks in advance.

  6. Nigel- Yes the CQWP is available in WSS 3.0. You will have to add it to your page through the Add a Web Part options.

  7. You are my hero! Thank you!Have you figured out how to get the “Name (linked to document with edit menu)” field into a CQWP?Thanks,Mindy

  8. Heather – Are you sure the CQWP is available is WSS 3.0?I don’t see it in my installation and it isn’t mentioned in the WSS SDK (although it is in the MOSS SDK).

  9. I am trying to roll-up announcements from all sites in the collection. I am filtering only content type of “Public Announcement” and I can get it to work, but I am trying to get the announcements to start and stop at specific times and dates. I am trying to use the QueryOverride with CAML. I have the fields set to date and time and I am using this CAML: <Where> <And> <Leq> <FieldRef Name=”PublishingStartDate”/> <Value Type=”DateTime”><Now/></Value> </Leq> <Geq> <FieldRed Name=”Expires”/> <Value Type=”DateType”><Now/></Value> </Geq> </And></Where>I just can’t get this to work. I have tried using the <Today/> value, but it seems to ignore the time. Like I said, I want to schedule items to appear on the front page at specific times and dates.Any help would be appreciated!~Jeremy

  10. After step 9, I get this error in all the webparts on the page:”Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.”Any thoughts what I might be doing wrong?Thanks.

  11. Hi Heather,Are you sure the CQWP is available in WSS 3.0? I can’t seem to find it in my installation and it isn’t mentioned anywhere in the SDK (although it is in the MOSS SDK).Thanks,Nick

  12. As a tip, if you’re going to use multiple properties in CommonViewFields – make sure there aren’t any spaces, and that there is no ; at the end.example : Body,Note;ArticleStartDate,DateTimeI couldn’t get it to work otherwise. Happy coding!

  13. I am encountering a problem with the ArticleStartDate property, and was wondering if you had any ideas.I’ve migrated all of the news postings of the past year from our previous CMS. I added in the Article Date field, and then populated it with the article release date (the date the news is to be made public).It works fine in the list, and I’m able to filter by it in the view. But when I pull this property out via the Content Query WP, the ArticleStartDate property seems to contain the date I posted the article itself?If I sort by it in the CQWP, they all contain the date I imported the item. This date appears when I print it to the page via the itemstyle.XSLAny thoughts? Maybe it’s pulling the XML property from the Publishing schema instead – which would give the item creation date? I’m stumped.Should I just recreate the list as a non announcements content type – and add in the columns manually?Thanks!

  14. Forget my earlier link. It’s to a sharepoint 2003 utility Wont import to 2007.Check this out though. Excellent!http://www.theegroup.net/Document%20Library/Forms/AllItems.aspxIts a sharepoint 2007 XML viewer! One of the menus isn’t really obvious – so be sure to right click on the XML itself and you can save it to your computer – easier to search through it that way. I also figure out my problem I posted about earlier – someone else had posted to the list so I was mistaken. Everything works beautifully!I was wondering if there was any way to add in the “Add new announcement” link at the bottom of the CQWP? I’m trying to edit the exported WP itself – but I’m just coming up errors.

  15. I am attempting to use the CQWP to display documents with an Approval Status of In Progress for the Approval Workflow. Any suggestions on how to do this?

  16. I am using simplified chinese version of MOSS2007, when i create a custom column by simplified chinese character, the url link shows like following:Field=%E6%88%98%E5%BD%B9%E5%90%8Dwhich i think is escapted, if there is way other than column property that i can get the true internal column name? i looked into sql server database but found no table related to column definitionthanks for any suggestion!nxliu

  17. I have been trying and trying to get the CQWP to fit my various needs and have never been able to get it to do so. I have gotten the non recursive part to work. But I want to limit the scope query to just 10 specific libraries, and not the whole site with lists and all. Is there a way to say I only want these 10 lists? I have tried to do just doc libraries but that is incomplete.

  18. OK I got the query to work right by adding in the list filter. Now it displays right but, when I RSS enable it. The feed does not work. I dont get an error or anything

  19. My current workaround: create the column by english name, then the internal column name is same with the name created, then change the display name to chinese namenxliu

  20. @Heather:Thank you for the detailed information, especially the list of field [email protected]:This is probably too late, and not very useful, but if I rememer correctly, the Content Query Web Part _was_ a part of WSS 3.0 Beta, and it’s no longer in the RTM. Such a pity really, because it would have been extrememly useful.Of course, I would love for someone to tell me that I’m wrong, and that the CQWP is still in WSS 3.0.

  21. Hi Heather,I read your article on customizing the custom query web part. I have a unique question that I have spent time googling for quite some time now but haven’t found any thing discussing this.My question is when you set the height and width to pixels, this displays the horizontal and vertical scrollbars. The request I am trying to satisfy is getting the right vertical scrollbar to display by setting respective height property, however, regardless of what pixels you use to set the width, I cannot seem to hide the horizontal scrollbar. Basically, I am trying to create a scrollable article list with only the right scrollbar and not the horizontal scrollbar at bottom and haven’t been able to find a solution to resolve this. Any insight you can provide would be appreciated.Jessie

  22. Heather, the Content Query web part is definitely not part of my default WSS 3.0 installation.Michael.

  23. hi can u tell me how to apply content search for audience based when particular user loggs in and he is targeted by audience he shuld be seeing documents related to that audience not othere than that how to do that

  24. Hi Heather,Just thought I’d throw this out there to see if you or anyone else has encountered this. I am able to following your instructions and get results pretty much as expected. The only problem I’ve had is when trying to filter by a custom field. I can get the field and its data to show up in the web part with no filters, but if I use the AdditionalFilterFields property to add the custom field to the drop-down, the results to do not return if I enter a value I know is there.Have you or anyone else experienced this? I’ve put this on the MS Sharepoint Forum, but to no avail yet.TIA

  25. I have always gotton the error messages for anonymous access for content query web part and summary link web part.”Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.”What could be wrong? Appreciate your help urgently!

  26. Hello Heather,I am using WSS 3.0 and have the same problem as Nick >Nick>Posted @ 3/14/2007 8:29 AM and>Posted @ 3/22/2007 5:22 AM>Heather – Are you sure the CQWP is available is WSS 3.0?When I try to add a web part and look in my list of web parts available, there is no Content Query Web Part there.Do I need to import it from somewhere first?Thanks,Jim

  27. Hi,I’m trying to use CQWP to present announcements on the page.Do anybody know howcome i can render the Body content of this list as it is (in my case HTML data) and to display it used predefined formatting.Appreciate any response.Shimon

  28. Hello Heather,I am new to Sharepoint and I was wondering if there was a way to print the content of a web part.For instance, let’ s assume that i am adding a rich text content web part to my page. Can I print just the content of my web part using a sharepoint out of the box tool?I tried javascript in the web part but this still prints the whole page with the navigation and all….

  29. Hi Heather, thank you very much for your great arcticles, they really save a lot of time!One thing that I’ve found out and think it is very important (just copy my own blog post with reference to your post):!!! Never use any spaces or even special characters when creating any fields in SharePoint !!!Maybe I’m not that good in it, but I haven’t found how to specify these field names as attribute names later in the XSLT transformations and wasted a lot of time. But then I checked how Microsoft handles fields like “Created by” and the like and – oh wonder – they named their fields “CreatedBy” and later changed the name to “Created By”. So the trick is to do the following:- Start to create new field (custom field in a list, site column etc.)- Choose a one-word name such as “PONumber” and save the new field- Open the field in edit mode again, change the name from “PONumber” to “Purchase Order Number” and save it again.The internal name used in the webpart definition file as well as in the ItemStyle.xsl is no “PONumber” and you don’t have to deal with complicated esacpings.Bye, Michael

  30. The CQWP is only available in MOSS when you have the Publishing features activated. It’s one of three WP’s that are specific to Publishing/WCM sites… the others being Summary Links & Table of Contents.

  31. To remove the markup tags from being displayed there is no need to call the function as per the link you provide, just change your xsl:value tag from:<xsl:value-of select=”@InternalColumnNameGoesHere” />to<xsl:value-of select=”@InternalColumnNameGoesHere” disable-output-escaping=”yes”/>

  32. i have successfully created my custom itemsytle template to show additional fields, but after configure my site to anonymous access, only title field is displayed when access in anonymous user, access with system user is OK, am i missed anything?the CQWP is configured to query only one content type, this content type is defined in site definition and created at root web(or site collection), the CQWP is placed in a layout page and used in subsite(web)

  33. Hi there,first of all thanks for the great post above – helped me a lot. I’m still a beginner when it comes to sharepoint customizing so I hope you can help me with these bunch of questions :)i created a template in the itemstyle.xsl to display the latest announcements. I added the title, the date and the author to the output.So, my first question is (maybe the easier one): what has to be changed within the attached lines of code(or elsewhere) to display a 24h-format of the time ?<xsl:variable name=”Created”> <xsl:value-of select=”ddwrt:FormatDateTime(string(@Created) ,1033 ,’dd-MM-yyyy hh:mm’)” /></xsl:variable>…My second question is probably tougher: i wanted to display with the CQWP the latest documents of a scope. no problem bout that.The Problem comes up when I wanted to display the name! of the document in the webpart – not the title. All i could find was the “FileRef”-Field, which displays the whole path of the document.I also discovered “FileleafRef” for the name of the document but couldn’t make it to display it in the webpart.Is there maybe a possibility with substring in combination of FileRef ? or how else can i display the name of the document ?…Finally, my last questions is what did i wrong in the following code? why does my CQWP do not show the first 200 chars of the content of my announcements and just the “…” ? must be a stupid mistakes by myself but couldn’t find it!<div class=”description”> <span style=”padding-left: 0px; font-size: smaller; text-decoration: none;”>Modified by <xsl:value-of select=”$Author” /> at <xsl:value-of select=”$Created”/> O’Clock </span> <div> <xsl:value-of select=”substring(@PublishingPageContent, 0, 200)” disable-output-escaping=”yes”/> …(more) </div> </div>i also add the following lines in the .webpart-file:<property name=”CommonViewFields” type=”string”>ExternalUrl,URL;PublishingPageImage,Image;PublishingPageContent,Note;</property>I am appreciate for any hints.Thanks,Tim(Hope i english isn’t too bad)

  34. Michael,I would say there is a problem with your installation. The content query web part is definitely part of the software and it would be listed with all of the other web parts.

  35. Nice article, thanks.How do we query image fields from publishing content ? Any sample would help.Thanks,Sridhar

  36. Hi Heather,Am I able to fix the css to the article page and not allow the content styles to overwrite it?For example, you write an article page, and everything you write in the text box has been fixed with your css and any changes to your text will not affect the css.Regards

  37. Hi,I’m trying to use the Content Query Web Part to display the messages from several discussion bords. All works well, but in the XSL I would like to be able to display the discussion in case of a reaction. It seems the returned data isn’t carrying that information and I have no idea how to add it. Is there a way to get both discussion and listname to display in the query results somehow? Thanks,Jasper

  38. Hello Heather,Special thanks to you and to everyone to share this valuable information…I have a case and I do not know if it face any of you.When I use the CQWP to querylist all documents inside specific folder in specific Document Library, It does not work.The error is: “Cannot save the property settings for this Web Part. The list name is not valid. The list name should refer to a list within the specified site: /listname/”Any idea how I can modify the CQWP to list the content of a folder inside Document Library ? Any help would be greatly appreciated…

  39. @James Posted @ 5/29/2007 5:04 PMHi Heather,Just thought I’d throw this out there to see if you or anyone else has encountered this. I am able to following your instructions and get results pretty much as expected. The only problem I’ve had is when trying to filter by a custom field. I can get the field and its data to show up in the web part with no filters, but if I use the AdditionalFilterFields property to add the custom field to the drop-down, the results to do not return if I enter a value I know is there.Have you or anyone else experienced this? I’ve put this on the MS Sharepoint Forum, but to no avail yet.————————————————————————–i had the same problem:i tried to filter a custom field, using this content query web part..i solved this problem creating a web part that gets my items using SPQuery and building a caml query. overriding Render method i can display all my items, including those that comes from the custom field.

  40. It seems that everytime I make a change to the XSL (e.g. ItemStyle.xsl) to experiment with formatting, I have to do an IISRESET.That is crazy. It adds about a 1min delay everytime I make a change. So adding anything more than a simple field replacement is pointless in SharePoint then.

  41. I know that the Content Query Web Part comes with out of the box MOSS, but we have WSS 3.0 and need something that will do the same things that the CQWP will do. Is there any way to install this web part on WSS 3.0? Alternately, do you know of any WSS 3.0 compatible web part that is able to do the same things as the CQWP. Specifically, we need to be able to merge 2 lists into one based on matching one column in one list with the same column in another (one list has employee paired with supervisor, the other employee with jobs, and we need a quick way to compile and keep updated supervisor with jobs with employee for email reminder purposes). Thanks!

  42. I’m having an issue with displaying the PublishingPageContent column in the CQWP after I have set up a custom publishing page layout. There is nothing to suggest that the publishing pages have been set up incorrectly, but I suspect the issue arises with the column type. I have tried RichHTML, FullHTML and HTML as an attribute but with no success – can anyone suggest another solution?BTW: great article. Very useful information.

  43. nxliu & all:The Tutorial is missing the step to Publish the ItemStyles.xsl file once checked in to make it available to other users (including anonymous users).Although this may be an obvious step to you experienced developers, it took a few hours off the life of one develeper.

  44. I used Publishing feature on MOSS and i want to get Publishing page from Pages Doc Where PubDate (or Check out date) less than current page. I used a ContentByQueryWebpart to get it. I tried protected DataTable Process(DataTable data) { DateTime PubDate = DateTime.Now; string strPubDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(PubDate); CrossListQueryInfo crossListInfo = new CrossListQueryInfo(); crossListInfo.ViewFields = “<FieldRef Name=”Title” Nullable=”True” Type=”Text”/><FieldRef Name=”FileRef”/>”; //”<FieldRef Name=”PubDate” Nullable=”True”/>”; crossListInfo.Query = “<Where>” + “<And>” + “<And>” + “<Eq><FieldRef Name=”File_x0020_Type” Nullable=”True” /><Value Type=”Text”>aspx</Value></Eq>” + “<Lt><FieldRef Name=”PubDate” /><Value Type=”DateTime”>” + strPubDate+ “</Value></Lt>” + “</And>” + “<Eq><FieldRef Name=”ContentType” Nullable=”True”/><Value Type=”String”>Article Page</Value></Eq>” + “</And>” + “</Where>”; //”<OrderBy><FieldRef Name=”Created” Type=”DateTime” Ascending=”False”/></OrderBy>”; crossListInfo.RowLimit = 15; crossListInfo.Webs = “<Webs Scope=”Recursive” />”; crossListInfo.Lists = “<Lists ServerTemplate=”850″ >”; crossListInfo.WebUrl = “/”; CrossListQueryCache xlqCache = new CrossListQueryCache(crossListInfo); data = xlqCache.GetSiteData(SPContext.Current.Site); return data; }It didn’t work, no data returnPlease help me

  45. There was a post on 3/6/2007 asking if you have figured out how to get the “Name (linked to document with edit menu)” field into a CQWP.I am also looking for a way to do that. Does anyone know how to do that?Thanks

  46. Nice article; one of the few articles i’ve managed to find on this subject. I’m new to Sharepoint and the whole customizing of web parts but have a question on this.I’d like to use the content query web part on my home site to display the latest news articles. I have managed to do this using the out of the box templates but want something a little smarter. I’d really like to display the articles in a table structure so that i can have articles in two columns i.e.<article 1> <article 2><article 3> etc…….I have to admit i’m struggling with how to go about achieving this; i’d appreciate any advice or help you could provide.Many thanks in advance,Grant

  47. Hi Heather,how can I create a content query web part that queries multiple types of lists? For example, I want to create a “News and Information” CQWP where items from both a Pages Library and a Document Library are returned. But when I start defining a CQWP, I am only presented with one choice for a list type.Is something like this possible in CQWP?

  48. This has been a great addition to the original article you link to. Excellent job! Made things much clearer to me.Some weirdness, though… made all my mods and everything is checked in and approved, yada, yada, yada… but, the mod only works when I’m logged out or editing the page. When I’m logged in and of edit mode, it doesn’t display the picture or the body text with “…(more)”. Doing the same thing for anyone who is logged in whether they have editing rights or not. Any tips would be appreciated.Also, I tried to do something similar to link to an existing list of external URLs… but, can’t find the field that makes up the title of the URL field. It simply displays the word “Blank”. And, it links to the list item instead of the URL. Any thoughts?Many, many thanks!

  49. First of all, thank you for your article, it helped me understand ECM blog better.My question is I can find most of the columns I require to create my CQWP, but if I was creating a CQWP that mimicked the Document Library columns, I’m unable to find the Type (icon linked to document) column. This would just be perfect item to show in my CQWP but I have no idea how to find the column name. Also in my document library (which contains podcasts), I’ve created a column called Content Description. I’ve used your “…(more)” example to cut down the Content Description inside the CQWP, but (and I understand how) when you click on more it loads up the MP3. What would you recommend I do, so that when I click on the more link, it displays the extra information that’s been trimmed? Surely I won’t hard code the URL in the XSLT?Many Thanks

  50. I have the same problem as JWM. I need this functionality but don’t have MOSS. Any ideas if you can help?

  51. Excellent article! Was looking for this… I was able to do just about everything I wanted with this.. Except for one thing… I cannot change the style of the link… I opened CONTROLS.CSS and fro mtheir found the item, link-item, etc css styles… I can change the size of the text… I can change the padding… But when I try to change the link color, I cannot. It defaults to the blue color… There has got to be another css style I am missing, but unsure which.. .Anyone know what I am missing? I am using these:.item {margin-bottom:6px;margin-top:6px;margin-left:4px;margin-right:0px;clear:both;}.centered {text-align:center;}.link-item, .link-item a, .link-item a:link{font-family:tahoma; font-size:8pt; color: #003399;text-decoration:none;}.link-item a:visited, .link-item a:active{color: #4167AF;text-decoration:none;}.link-item a:hover{color: #000000;text-decoration:underline;}.bullet{border-style: none;border-color: inherit;border-width: 0;vertical-align:top;background-image:url(“/_layouts/images/lstbulet.gif”);background-repeat:no-repeat;background-position:left;padding-left:10px;padding-right: 0px;}

  52. Im looking for any way of displaying Name (linked to document with edit menu) in the CQWP. but I did not found any way… Can any bosy help us?many thanks,Iker

  53. After reading this and a couple of other posts, my main objective was to ‘wrap’ all items from a list in a DIV tag, with minimal impact to ContentQueryMain.xmlI’ve found something not posted in any of these blogs/posts/comments that may well indicate further developments on this area.Both Header and ItemStyle have a ‘mode’ attribute.ContentQueryMain call three templates types: CallHeaderTemplate, CallItemTemplate and CallFooterTemplate.The problem is that only the first too actually call something else, while the last one, just add a DIV tag for the footer.My change, that I believe will be implemented in next MOSS release, was to add to ContentQueryMain ‘CallFooterTemplate’ template:<xsl:apply-templates select=”.” mode=”footer”></xsl:apply-templates>Then inside Header.xsl, you can create two GroupStyle templates using both modes ‘header’ and ‘footer’, where the tags for open/close tables, divs, and everything else can be placed.Works very good, with minimal changes to ContentQueryMain.xml, and using the same architecture that MS is using for Header and Item.Regards,Lucas Persona

  54. I have “Summary Link Web Part” issues:On fairly frequent occaisions my users are greeted to the “Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.”While other times everythingt works properly. Any ideas what is going on?

  55. I am trying to create a publishing site, which should be an aggregation page and a library of article pages. My problem is I could not locate my pages through CQWP. When I create a new article page, it was saved in the page libray by default. But after I set the query source as the list (page library), I could not find “page library” from the List Type drop-down menu. Therefore, the CQWP showed no item event I chose “all content types” for the content type. I had to move all pages to the document library and then CQWP worked well. How to solve the problem? Thanks!

  56. To Marina Renee and Su:RE: “Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.”I had the same problem and it turned out to be a stylesheet I’d edited that was not checked in, so the admin login could see it, but no one else. Once I checked it in, all was well. Try that.

  57. I was following your article on styles for Content QueryThe following raised a nit-picky question:—————————————Change the name and match properties in the Template tag to a unique name of your choice:<xsl:template name=”MyCustomStyle” match=”Row[@Style=’MyCustomStyle’]” mode=”itemstyle”>————————————What if you want your style name to have spaces, like “My Custom Style”? The default styles have names like “SmallText” or “LargeText” but you can select these from the UI dropdown as “Small Text” or “Large Text”. How is that done?

  58. I was struggling with figuring out how to filter a CQWP for a while and found a solution that’s a little easier than the one below. Rather than creating your custom fields in the settings of the List you are querying, create a content type and create the fields in the content type. Then when creating your list, select existing fields rather than creating new ones. This way, they appear in the UI of the CQWP Filter. They are also available to any other list. D.——————————————————-Just thought I’d throw this out there to see if you or anyone else has encountered this. I am able to following your instructions and get results pretty much as expected. The only problem I’ve had is when trying to filter by a custom field. I can get the field and its data to show up in the web part with no filters, but if I use the AdditionalFilterFields property to add the custom field to the drop-down, the results to do not return if I enter a value I know is there.Have you or anyone else experienced this? I’ve put this on the MS Sharepoint Forum, but to no avail yet.————————————————————————–i had the same problem:i tried to filter a custom field, using this content query web part..i solved this problem creating a web part that gets my items using SPQuery and building a caml query. overriding Render method i can display all my items, including those that comes from the custom field. —————————————————————————-

  59. Thanx for this article. I have a Table Of Contents web part i my SharePoint site. I want to change the font color of the items listed in this web part. Can someone help?Remandlo

  60. Not sure if this is the rigt place to post it but I have a ui problemthat might be related.I wish the standard list in wss would have been like in hotmailwith checkboxes multiple selection that i could do simple stuff like delete/copy/move etc.Would that be a customization of cqw or I need to write my own webpart? I see though in ECM that Site Content and Structure has this functionality. I wish to use it in any simple wss list.What is your suggestion?Thanks.

  61. I have set up a page that contains two web parts – one is a product list, the other is a grouped view (default collapsed) of a library that also includes a product column. I have established a web connection between the two web parts, so that when a user selects one of the values in the product list, the library is filtered to display only items with product = that value. All appears functional at first glance – selecting a product decreases the number of items in each grouping (shown in parentheses). However, when the user expands the grouping to display the documents, all documents appear – even though the number in parentheses remains the same (the lower, filtered number). Furthermore, if I edit the view so that the groups default to expanded, the filter works perfectly. It seems to break only when the view is collapsed and the user clicks to expand it. Ideas?

  62. Hi Heather,I need to display items from a picture gallery using a content query part, but I’m having trouble accessing the right data. Essentially, I would like to display the pictures in a library with as much functionality as possible from a web part page on a subsite of the main site that hosts the picture library.Firstly, I would like to get the thumbnail url for each item, as well as a link to the detail view for the item – unfortunately, the only useful information I seem to be able to get from the CQWP out of the box is the Title, FileRef and LinkUrl. I’ve looked through the schema for the picture library and found a bunch of “computed” columns for thumbnail and nothing obvious for getting the link to the item’s detail view. I tried adding one of the computed columns to the webpart file but that didn’t work for me. Is this at all possible in a CQWP, or am I going to have to do this in a custom webpart? Many thanks in advance 🙂

  63. I am not able to get the file size innername for the documnet library. I can see the x0020_ows_File_x005f_x0020_Size. But it doesn’t return any value.

  64. HelloI’m working on this site, and this things has been bugging me for days now.Its all working just fine and i’m getting data from 3 col. from my custom list. A singel line text “title” multiline “body” and a image “publishing…image something ;)My problem is (and ill try my best to explain)When the page is rendered, stuff like <br> is not making a break, but its visable so people can see it between the words. I know there are 3 options for me to choose in col. settings “simpel” RFT” and one more. If i choose simpel it looks good, but I can only write a boring text with a few spaces. If I try to chance to RFT its still simpel text, but it shows the <br> and “&bsp” or something like that, can’t remeber the exact chars.Anyone got any idea how to make the CQWB show the text as html when i choose RTF(RFT) ;)is there some kinda template i can add to my code in itemstyles.xml, or code maybe?

  65. The ListViewWebPart has alternating white and gray rows. Anyone have code to make the CQWP do the same?

  66. anyone knows how to change the output from a body col.This is how it should be——————–tekst til nyhed 2 HEJ——————— This is how it looks like ———————<div>tekst til nyhed 2&nbsp;<br>&nbsp; <br><br>HEJ <br></div>———————I know i can choose normal text over RTF, but i want to be able to see it in html.Anyone got a solution to this?

  67. Awesome, Dave – thanks for the info. I tried your suggestion and it fixed my filter problem without code!

  68. We are working on a news/press releases section of our website and I am using the Content Query Webpart quite heavily for pulling information. For instance I have created a page called Archive 2006 that has a CQWP that pulls all news releases from jan 01 – dec 31 2006. I told the web part to group them by category and it is working fine and dandy. The problem is the header for the groupings does not match our style. I know that the style it is using is groupheader item medium which is located in header.xsl(Where i may make a custom header style that does it by month rather than category). The problem i’m trying to address here is I want to change the “groupheader item small” style to something of my liking. I have tried replacing it wtih my own custom style located in my stylesheet for my masterpage/page layout, but its not reading the information for some reason. Any help would be greatly apprecaited This is located in header.xsl, I want my own custom div here! <xsl:template name=”DefaultHeader” match=”*” mode=”header”> <div class=”wc_groupheader_item_ medium”> <xsl:call-template name=”OuterTemplate.GetGroupName”> <xsl:with-param name=”GroupName” select=”@*[name()=$Group]”/> <xsl:with-param name=”GroupType” select=”$GroupType”/> </xsl:call-template> </div>

  69. Hi, I need to populate the filter value of the CQWP automatically, that is when a page, created depending on a specific page template containing the CQWP, the CQWP filter value gets populated with the page name or title automatically, is this feasible?

  70. Advanced Customization”OK I got the query to work right by adding in the list filter. Now it displays right but, when I RSS enable it. The feed does not work. I dont get an error or anything”I have the same problem, did you ever figure it out? I can’t find an answer on your problem among the posts. If you know, please post it! Thanks!

  71. Hi,I was able to follow Heather’s CQWP customization and further enhancing it using Paul’s grid table format, but was having issues displaying image field type. It only shows the URL of the image with a (,) at the end. e.g. (https://myweb.com/Marketing/images/icn-order.gif, )<property name=”CommonViewFields” type=”string” >Title, Text;IcnOrder, Image</property>Any help will be much appreciated.Mike

  72. Great articles.I have followed Heather’s customization of CQWP and enhancing it further with Paul’s table grid format. I’m having issues displaying image field type. The image appears as url with a comma at the end instead of the image itself. e.g. http://web/marketing/images/icn-order,

  73. I’ve carefully tried to customize the CQWP using the 3 steps here and in many blogs. Step 1, where you modify the itemstyle to display available columns, fails. On the site, the CQWP just display a message, “unable to display this web part….”What to do? How to even begin?

  74. I just resolved my issue earlier on how to display a custom image fields from a content viewer webpart using table/grid style.Regarding the issue I was having last time where it doesn’t display the images from the grid view but instead displays the text (https://myweb.com/Marketing/images/icn-order.gif,). I manage to resolve it with the help of SharePoint Designer by creating a custom view and selecting the custom columns that I want to display. I found out that the images column type are shown as URL(comma) (e.g. https://myweb.com/Marketing/images/icn-order.gif,). The current format is Text, so I have to change it to Picture from the Common xsl:value-of Tasks -> Format as PICTURE. This change the display to the custom images that I wanted to show. I copied the code to show the image ( <img border=”0″ src=”{substring-before(@IcnOrder, ‘, ‘)}” /> ) And in the ItemStyle.xsl file I have to change the @PICTURECOLUMNNAME to the code <img border=”0″ src=”{substring-before(@IcnOrder, ‘, ‘)}” /> . Then save it. Now my table grid results to show the text as well as the custom image type columns.

  75. Heather, thanks for your very helpful blog.I was also running into the problems the CQWP (with CopyUtil.aspx) and anonymous users. I created a quick blog entry that describes how to create your own Item Style for linking to blog entries (notice, the example is ‘hard coded’ for links to blog posts):Content Query Web Part (CQWP) with Anonymous Accesshttp://blogs.edork.com/MikeGeyer/Lists/Posts/Post.aspx?ID=20 I hope this helps and thanks again for your blog. – Mike

  76. Heather, Great POST!!! I am doing a rollup based on the Posts list of a Blog site in the same collection, but I can’t seem to get the body to display. Following all the steps that you mentioned here along with the steps from the URL that you reference, I am able to get a nice rollout that looks like this:BLOG UPDATES2008/01/23 08:55:00 <Title> Author: <USER>  Created: 2008/01/22<BODY>…more But the BODY part mentioned above, I can’t get no matter what I do. I add this to the ItemStyle.xsl:<div class=”description”><xsl:value-of select=”substring(@Body, 0, 200)” disable-output-escaping=”yes”/>href=”{$SafeLinkUrl}” target=”{$LinkTarget}” title=”Lees meer”>More…</div>Then I changed the CommonViewFields property in ContentByQueryWebPart.webpart to read: <property name=”CommonViewFields” type=”string”>Body,RichHTML</property>Should work, right? Well, it doesn’t seem to come out, for some reason. Am I missing a step somewhere? Would love to get some guidance from you. Best Regards,Alan

  77. HiThanks for the article – I found it extremely useful.I’m trying to use a content query web part to show some text and an uploaded image (an attachment) from a custom list. I can work out whether each item has an attachment or not using the attachments property but I can’t for the life of me figure out where the file is or what the filename might be.Is this some kind of known issue which I will never resolve or am I just missing the answer?ThanksTim

  78. Well I finally got it to display more than one field but don’t know how to get breaks in. I have Address and City so far, but they are displaying as follows:123 MainStNew YorkMy code is:<div class=”description”> <xsl:value-of select=”@Column11″ /> <xsl:value-of select=”@Column13″ /> </div>Column11 being Address and Column13 being city. How do I get a simple page break between the columns so they display:123 Main StNew YorkThanks in advance!!- Peter Hack

  79. Hi Heather,I am trying to customise the Search Core Results Webpart to display news articles.I want to display internal Field Names such as “PublishingPageContent”,”Body” ,How do I get access to the Internal Field NamesThanksChander

  80. Great post. Was wondering if you have come across how to be able to expand/collapse a grouping header? I am able to get everything else working correctly but also want the functionality to be able to expand/collapse headers with the CQWP.Thanks

  81. Hi Heather,My custom CQWP is connecting to an Announcements list in another site. It works fine, in that I see the body and, when I click on the announcement title or ‘more’, the WP takes me to the DispForm.aspx for that announcement.The question I have is, how do I get the DispForm.aspx to return me to the page containing my custom CQWP? Currently, when I click on ‘Close’ button on the DispForm.aspx page, it get redirected to the actual announcements list in ‘all items’ view. What I would like to do is have the page send me back to the page containing the custom CQWP.Any ideas?Kris

  82. Very good post indeed!Just a quick question.. Instead of exporting and uploading the webpart, I simply edited ContentQuery.webpart found in /_catalogs/WP using SharePoint Designer and it seemed to work like a charm… have I done something wrong or just in another way?Best Regardshenrik

  83. Peter,Insert a space at the end of your first “value-of” statement, or put the two statements on the same line with a space between. Your XSLT markup will render anything that’s not within an XSLT tag as literal text,in this case, a simple space.Hope that helps.MarkEndUserSharePoint.com

  84. User is also an appropriate data type for columns where you chose to store a person. For example if you want to display the created by or modified by person.Scott

  85. excellent article, got everything working, butHow can I translate it into different language???thansk

  86. Has anybody found out an annswer to this:I was wondering if there was any way to add in the “Add new announcement” link at the bottom of the CQWPUrgently waiting for a workaround.Thanks.

  87. Hello everyone, I have followed along Heather Soloman’s post here: http://www.heathersolomon.com/blog/articles/customitemstyle.aspx and it is very good except I what attempting to query is a document library that and would link my CQWP to show each document’s specific document type image (such as a .doc would have a MS Word doc image in front of the title) similar to the way the Summary List WP shows data. I have attempted to add: <xsl:value-of select=”@PublishingRollupImage”/> into the code and was not sure if this was the correct route to go down. If you click on the document library that is being queried there is a column called “types” that shows the images of each file and is linked to them. When I look at the column groups under content types I cannot find this column. When I add:<xsl:for-each select=”@*”> P:<xsl:value-of select=”name()” /></xsl:for-each> I see the value @PublishingRollupImage returned. is this the column I am looking for? If so how do I make it appear. Another Questions: For the description code I wanted a “(more…)” link: <xsl:value-of select=”substring(@Detailed_x005F_x0020_Description,1,50)” /> …(more) </div> but some of my documents don’t have desriptions and therefore the link is not necessary for them. What is the appropriate if statement? or coding to make this the link conditional to only appear for documents with descriptions? I am thinking something like this:<xsl:if test=”string-length($Detailed_Description) != 0″> something like thaT? Here’s a look at the full Item Style code: <xsl:template name=”CustomStyle” match=”Row[@Style=’CustomStyle’]”mode=”itemstyle”> <xsl:value-of select=”@PublishingRollupImage”/> <xsl:variable name=”SafeImageUrl”> <xsl:call-template name=”OuterTemplate.GetSafeStaticUrl”> <xsl:with-param name=”UrlColumnName” select=”‘ImageUrl'”/> </xsl:call-template> </xsl:variable> <xsl:variable name=”SafeLinkUrl”> <xsl:call-template name=”OuterTemplate.GetSafeLink”> <xsl:with-param name=”UrlColumnName” select=”‘LinkUrl'”/> </xsl:call-template> </xsl:variable> <xsl:variable name=”DisplayTitle”> <xsl:call-template name=”OuterTemplate.GetTitle”> <xsl:with-param name=”Title” select=”@Title”/> <xsl:with-param name=”UrlColumnName” select=”‘LinkUrl'”/> </xsl:call-template> </xsl:variable> <xsl:variable name=”LinkTarget”> <xsl:if test=”@OpenInNewWindow = ‘True'” >_blank</xsl:if> </xsl:variable> <div id=”linkitem” class=”item”> <xsl:if test=”string-length($SafeImageUrl) != 0″> <div class=”image-area-left”> <img class=”image-fixed-width” src=”{$SafeImageUrl}” alt=”{@ImageUrlAltText}” /> </div> </xsl:if> <div class=”link-item”> <xsl:call-template name=”OuterTemplate.CallPresenceStatusIconTemplate”/> <xsl:value-of select=”$DisplayTitle”/> </div> <div class=”description”> <xsl:value-of select=”substring(@Detailed_x005F_x0020_Description,1,50)” /> …(more) </div> </div></xsl:template></xsltylesheet>

  88. Hi Heather,I am hoping you can help me on this.I am trying to display a summary of all tasks within a specific group of subsites. For the most part it is working after following yours and other content query web part posts. The only column that I am unable to display is the “Assigned To” column. I use the name and type stipulated in the Schema file but it does not show anything. I have even tried changing the settings of the column itself on the one test task list I have at the moment and that is not working.Do you have any ideas on this?Many Thanks

  89. I was wandering how i might go about creating a custom image library that allows the adding of an alt tag when you upload the image in the first instance?As by default, sharepoint only promps you to add an alt atg when you add it to a page or site.Many thanksRich

  90. i need to have a more.. link to another page after i display the title, description elements i dont want more with each item in the CQWP list items,for eg:title1 description1title2 description2 more..

  91. Hi Heather,These seem to be nice solutions, but I have a problem. I cannot see the body content. I’m using Telerik Radeditor instead of RTF-editor in my announcement list could that cause the problem?

  92. Hi HeatherFinally I got these working. Except I gotta be able to show attachements. I know how to add them do the sharepoint default templates, but with these cannot get them working. I also need to show the date/time. Could you help me please?

  93. When editing the Web Part, “MyCustomStyle” is not appearing in the Item Style drop down. I did publish the ItemStyle.xsl file and restarted IIS. I am new to SharePoint. Anybody have any ideas why?

  94. I’ve followed the instructions to the letter, but when I try to upload the webpart I get the error:”The file you imported is not valid. Verify that the file is a Web Part description file (*.webpart or *.dwp) and that it contains well-formed XML.”What am I doing wrong?

  95. I am also having the same problem as Kris White: “how do I get the DispForm.aspx to return me to the page containing my custom CQWP”?Also, I have searched for DAYS looking for info on how to do Conditional Formatting with the CQWP and have come up blank (I’m not much of a developer, so I am looking for some step-by-step example) and I’m hoping that this isnt a difficult task.I have announcements lists where some of the announcements are more important than others and I’d like to have them shown in red (can you also make blinking work?).

  96. What is the field type for Created by/Modified by fields? How do u specify the type ‘Person or Group’ in XML ?

  97. Saw some people asking about “Name (linked to document with edit menu)”, its internal name is “LinkFilename.” You can get the SPField object with list.Fields.GetFieldByInternalName(“LinkFilename”);

  98. Hi Heather, I’m trying to show post in my CQWP following the Heny Ong article http://blog.henryong.com/2008/06/15/how-to-customize-the-content-query-web-part-xsl-to-aggregate-blog-posts/ and this one. I can’t see the body of my posts, I think that may be I’m not using the right field name or type.I don’t have any field called “Body” in the post content type, I have a “Description” field and his internal name is “Body” I was trying to get it works using the field types: Description -as in the Henry blog-, RichHTML, Text and Note but no one works for me.Did you try this ??Can you give me some tips about it?This are the customizations of my .webpart:<property name=”DataColumnRenames” type=”string”>Body, Description;</property><property name=”ListsOverride” type=”string”><![CDATA[<Lists><List ID=”98fcc706-2d1b-44b9-a8bb-f3524ff20cb6″/> <List ID=”1c3df4ae-2b6e-4f1a-87dd-fcc12130c5d8″/></Lists>]]> </property> ( I’ve 2 blog sites)<property name=”CommonViewFields” type=”string”>ExternalUrl,URL;PublishingPageImage,Image;Body,Description;</property>and this is my xsl:template portion:<xsl:template name=”EstiloDetalle” match=”Row[@Style=’EstiloDetalle’]” mode=”itemstyle”><xsl:variable name=”SafeLinkUrl”><xsl:call-template name=”OuterTemplate.GetSafeLink”><xsl:with-param name=”UrlColumnName” select=”‘LinkUrl'”/></xsl:call-template></xsl:variable> <xsl:variable name=”SafeImageUrl”><xsl:call-template name=”OuterTemplate.GetSafeStaticUrl”><xsl:with-param name=”UrlColumnName” select=”‘ImageUrl'”/></xsl:call-template></xsl:variable> <xsl:variable name=”DisplayTitle”><xsl:call-template name=”OuterTemplate.GetTitle”><xsl:with-param name=”Title” select=”@Title”/><xsl:with-param name=”UrlColumnName” select=”‘LinkUrl'”/></xsl:call-template></xsl:variable> <xsl:variable name=”Created”><xsl:value-of select=”ddwrt:FormatDateTime(string(@Created) ,1033 ,’dd-MM-yyyy’)” /></xsl:variable> <xsl:variable name=”LinkTarget”><xsl:if test=”@OpenInNewWindow = ‘True'” >_blank</xsl:if></xsl:variable> <xsl:variable name=”Author”><xsl:call-template name=”OuterTemplate.GetGroupName”><xsl:with-param name=”GroupName” select=”@Author”/><xsl:with-param name=”GroupType” select=”‘User'”/></xsl:call-template></xsl:variable> <div id=”linkitem” class=”item”><xsl:if test=”string-length($SafeImageUrl) != 0″><div class=”image-area-left”> <img class=”image” src=”{$SafeImageUrl}” alt=”{@ImageUrlAltText}” /></div></xsl:if> <div class=”link-item-large”><xsl:call-template name=”OuterTemplate.CallPresenceStatusIconTemplate”/><font size=”2″><xsl:value-of select=”$Created”/></font><br/><xsl:value-of select=”$DisplayTitle”/> <div class=”description”><span style=”padding-left: 5px; font-size: smaller; text-decoration: none;”>Posted by <xsl:value-of select=”$Author” /><br/><br/></span></div> <div class=”description” style=”padding-left:5px; color:#333333;”><xsl:value-of select=”substring(@Description, 0, 200)” disable-output-escaping=”yes”/></div></div></div></xsl:template>Thanks in advance!!!

  99. How would I apply this to a list? I created a Custom List that contains information about a project, such as Company Name, Project Name, Project Code, Site Description, Site Address, etc. When I added the CQWP it only displays the first column, Company name. How do I get it to display all of the columns created in this web part without revealing the list I populated the information in? Basically the end result–if possible through this route, is to have the list of project information displayed on each site that a compay will be assigned to be able to see this CQWP that displays their Company Name, Project Name, Project Code, Site Description, Site Address, etc. I am trying to follow the instructions from both this site and Configuring and Customizing the Content query web part site but I get lost after Finding the Additional data (Heather’s page) and Step 3 (ECM Team Blog). Please help shed some light on this confused designer…if I should even be called one.

  100. this may be a silly quesiton, and i’ve pretty much mastered customizing master pages and deploying them as features etc. i’ve also successfully deployed a custom css that overrides the out of the box parts that i needed to customize, but i’m totally lost on how to enforce fixed widths on the web parts. Can anyone give me advice on maybe some detail i’m missing?

  101. I have a custom field in my document library I am trying to get to appear. It keeps coming up blank. Any ideas.

  102. -*- URGENT -* -I want to display content starting from 4th Page sorted by Created DESC. I had set the items number limit to 5.Can anyone tell me how to display pages starting from Nth Page.Can I do the same using the CAML query. Any examples will be of great help.Thanks in advance.

  103. I could hug you right now, Heather! This is awesome! This helps a lot most especially when listing all the fields being passed. What an eye-opener. Thanks!

  104. @Lauri VaittinenHi Lauri,I have the same problem here, i need to get the attachments of a list item and display them.Have you figured out how to do that ?

  105. This looks useful but I get completely lost at steps 12 and 13. I am using a document library as the source of the information for the CQWP and even after following the instructions above, I cannot get it to work.

  106. Hi,Does anybody know whether it’s possible to have a subquery. Let me explain.We have a list which we query through the CQWP. The list has valus that are a lookup from another list. What we want, is get values from the linked list.Could anybody explain whether that is possible and how it should be done?Thanks!

  107. Does anyone knows how to add headers and footers while using group view in CQWP. I tried adding the table headers in the header.xsl as follows <div style=”display:none” id=”linkitem” class=”item”> <table border=”1″> <tr> <xsl:for-each select=”@*”> <td><xsl:value-of select=”name()” /></td> </xsl:for-each> </tr>Then i had the following line in the itemstyle.xsl <tr> <xsl:for-each select=”@*”> <td><xsl:value-of select=”.” /></td> </xsl:for-each> </tr>and the closing tags were in ContentQueryMain.xsl in at the following lines 165 <xsl:template name=”OuterTemplate.CallFooterTemplate”> </table> </div> </xsl:template>But somehow this is not working. I would appreciate if anyone can help me getting this workSameer.

  108. Thank you Heather for this article; it was extremely helpfull to design the data that is displayed through the CQWP in the way I want. As you mention in the last paragraph, it might get tricky though to track down their columns correct names.Right now I’m getting really desperate and frustrated, because all the column names I process in order to display data from the discussion board are empty. I’m using the Moss 07 Out-of-the-box Discussion Board and I checked out all field elements from the schema.xml inC:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEFEATURESDiscussionsListbut without any results. Any further ideas how to track the content of the data that is passed through the CQWP?In my particular case, I want the thread name to be displayed correctly. It is only displayed in the starting message of a new thread, while all replies are titled “blank”…Thanks, Martin

  109. Hi HeatherHeather has address addressed the steps to use to reveal additional fields via the CQWP. However, despite having followed these steps (and the advice on the MSDN blog), I could not reveal a Choice column with the display name News Story Topic.After a greeat deal of angst I discovered that there are two names per site column – the internal name and the display name listed in the Site Columns Gallery and the content type. It is the internal name that has to be used to reveal the additional fields. The internal name MUST not contain spaces. The steps to follow are first, enter the column name without spaces and then second, come back and edit the column name to a more user-friendly format should it be deemed necessary.These few paragraphs have come after days spent trying to resolve the issue at my end. Daniel Pollar also refers to this fact in his blog:Spaces in Site Column Names – How to avoid the _x0020_ naminghttp://httpcode.com/blogs/CommentView,guid,FB4A2A24-C1E7-4F23-9317-5AE7F1430036.aspx#c9536b9b-d6d1-4fc8-82ec-ec745f3a347cCheersDavid

  110. I was wondering if this applies to MOSS 2007 … you mentioned the Schema file but not which one? Are supposed to know? Seems I was able to do everything else except the schema part because I am working with an Image library that I want to display the thumbnail, image, and description in a particular way (CSS styles applied). Any help would be nice.

  111. Hello and thank you for this article.I have two questions:a)In step 17:If the field has a dash in its name (for ex. bog-comments – the field name is :BoG%2DComments), how you write it in property name=”CommonViewFields” ? Bog-comments, ‘Bog-Comments’ , BoG%2DComments or ‘BoG%2DComments’;b)Also, if the field name is something like Field=%CE%97%CE%BC%5Fx002F%5F%CE%BD%CE%B9%CE%B1%5Fx0020%5F%CE%BA%CE%B1%CE%B9%5Fx0020%5F%CE%8F%CF%81%CE%B1%5Fx0020%5F%CE%95%CE%BC%CF%86%CE%AC%CE%BD%CE%B9%CF%83%CE%B7%CF%82 (non latin characters) how do you reference it ??Thank you

  112. Hi Heather,I am using a content query webpart for displaying links.I am using a links list. I need to paginate the links as I show only 10 links at a time in 2 columns. Can you tell me how can I show pagination in the CQWP ?

  113. hi How do i edit the Itemstyle.xls and the .webpart file if i want to aggregate forums on the parent site from a sub site?I’d like to show the Forum Thumbnail to appear (image of user who created the forum thread) as per normal Forum List Web Part.it only shows the title and the MORE link. no body or image appeared.

  114. Hi Heather:In following your instructions and trying to figure out what was what, I think that I may have accidentally typed in a character or deleted something I shouldn’t in all the fiddling with the code because after I successfully got to step 11 a few times, the last try gave me the errorAn unexpected error has occurred.Web Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator. Troubleshoot issues with Windows SharePoint Services. May I ask how to &amp;amp;quot;reset&amp;amp;quot; the ITEMSTYLE.XSL file back to the Site Definition and restore it to its original state? Now that I know better, I will copy the original content to a text file or something to preserve it BEFORE I attempt to make changes.Thank you

  115. I have:<xsl:for-each select=”@*”><td><xsl:value-of select=”.” /></td></xsl:for-each>But all the values are empty, yet I can see data in list?Is there a hidden display value needed?Thanks,Jason.

  116. Here’s a puzzler: I’d like to keep my custom templates in another file, custom.xsl. I add in the appropriate tag right below the xsl:stylesheet in ItemStyle.xsl: <xsl:include href=”regisLinkItemStyle.xsl” />When I save the stylesheets and modify the CQWP in sharepoint (using the tool pane), the CQWP immediately displays”Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.”I’ve tried making custom.xsl an empty stylesheet, and the error persists. From this, I gather that sharepoint just won’t work with itemstyle.xsl containing the include. What are your thoughts?

  117. Hi Heather,Great article. I like some of the others need to display the list of attachments for a list item. How is this possible? Also would it be good practice or even recommended when the webpart is exported to link to custom xls files (rather then itemstyle and header) as a precaution against future service packs etc? Have you done this anywhere?Thanks,Michael

  118. Hello,I have a particular problem regarding the content query webpart, let me know if you can help me outI want to implement the CQWP to retrieve the last 5 Post of 3 different discussion boards, I have already placed the query correctly and I have modified the ItemStyle.xsl in order to display some more information, the tricky thing is that among this extra fields to display I want to display the # OF REPLIES PER DISCUSSION, and I just havent found out the way to pull this info, seams there is no variable or column with this data.Thanks for you supportRegards,

  119. I have a Page layout created from a content type. I have created a custom CQWP for fetching the data from the content type. I want to sort based on most frequently accessed. Page layout is buit for services. and the custom CQWP will display the data based on the filteres mentioned and here i want to sort the services based on most frequently accessed. Could you please any idea about implementing the same.ThanksSankar

  120. Awesome long lasting post!Quick question: Is there a way to add a graceful message to the CQWP for when the query returns no results?Something like: There are no new announcements at this time.Thanks!

  121. When adding custom fields to the Content Query Web Part, you might run into problems when fields have spaces in their name. If you run into this do the following solution: rename the field in the DataColumnRenames property of the Web Part. Example: Say I have a field for my ‘department name’, which is a single line of text (type: Text). Field Display Name: Department NameField Internal Name: Department_x0020_Name1) Content Query Web Part properties <property name=”CommonViewFields” type=”string”> Department_x0020_Name,Text;</property><property name=”DataColumnRenames” type=”string”> Department_x0020_Name,DepartmentName;</property>2) ItemStyle.xsl <xsl:value-of select=”@DepartmentName”/>The query is executed using the original field name. The renamed field can be used as parameter in your XSL template.

  122. This article has been of immense help. Thanks Heather.I am having one problem however. I can’t seem to add a ‘Person or Group’ field. It displays the fields that already exist (i.e. AssignedTo, Editor, Author) but not ones I create. I tried with field type ‘User’ but it doesn’t work. I looked in the SCHEMA.XML file and ‘AssignedTo’ uses ‘User’. I’ve Googled it to death but no info on how to reference People or Group fields that are user created.

  123. Great article! Is there any way to just return the Date portion of a DateTime datatype? I am trying to retrieve either @Created or @Modified, however it shows the time in GMT and is not very appealing. Thank you!

  124. I keep getting this error after Create the Custom Item Style, #10:An unexpected error has occurred.Web Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator. Troubleshoot issues with Windows SharePoint Services. Can you please tell me what is happening/how to fix it?Thanks

  125. Hi, Great wee blog this. I have been working off this for a day or two now and finally got things going this morning.I was wanting to get tasks from the master site shown in a subsite based on a filter of Assigned to: Got the view going but only able to get the task name and description. Cant get it going on the same look as the tasks ie table.Anyone done anything similar if they could fire a few hints my way i would be great.Cheers

  126. I was able to update the style sheet for the CQWP and all the fields are displaying correctly for me but when other users can not see the changes. I have tried looking to see if I need to make the changes to the style sheet on the internet with no luck. Any suggestions?

  127. Hi Heather,This is a great article and has helped me in the past. I’ve amend a CQWP to list news items taken from article pages. This worked really well. I’d now like to use something similar in order to view information from a blog. What I’m after is the CQWP to list the Headline (title) and Body (only the first sentance though) from a blog that we use on our intranet. My issue is that I can’t find the Conent type for a blog – I would assume it’s similar to an announcement!? I’m struggling with the FieldTypes for the Body text – whatever I’m trying isn’t working. Has anybody tried this with some success? Any help or insight would be appreciated.

  128. I’m trying to get my cqwp to pull an image forward from a list, along with the title and description. I have it pulling the title and description but can’t get the image to display. I added the ImageURL field to the commonview fields and I’ve edited my itemstyle.xsl.Any ideas?

  129. When i click on the more link it takes me to Dispform.aspx, is there a way of making it take me to the full story page?Thanks in Advance

  130. Hi Heather,I have created a custom style by moifying ItemStyle.xsl and Header.xsl. The style is like collapsible and expandable grouping of items. If I apply sort option to the item, it sorts only headers…not the items inside the group header. Is there any way we can sort items inside group header….after aplying groupby.Thnks in advance.

  131. Hi Heather,Great post! It’s been enormously helpful. I’ve ALMOST got everything working the way we want but….I would like to format the group header which is based on a custom field – ideally to group the results by date, which is working, but the datetime field is unformatted. I added the custom field, start_datetime, to the .webpart additionalgroupandsort property, so it appears in the GUI as an option to group by and that works fine. I’m struggling to figure out where this field should be formatted. Adding the formatting code to the ItemStyle.xsl just causes the field to be displayed for each item and the field isn’t defined in the Header.xsl, which is where I think the formatting code should go. Any advice would be most welcome!Thanks!Heather

  132. I have: <xsl:template name=”CustomStyle” match=”Row[@Style=’CustomStyle’]” mode=”itemstyle”> <xsl:variable name=”SafeImageUrl”> <xsl:call-template name=”OuterTemplate.GetSafeStaticUrl”> <xsl:with-param name=”UrlColumnName” select=”‘ImageUrl'”/> </xsl:call-template> </xsl:variable> <xsl:variable name=”SafeLinkUrl”> <xsl:call-template name=”OuterTemplate.GetSafeLink”> <xsl:with-param name=”UrlColumnName” select=”‘LinkUrl'”/> </xsl:call-template> </xsl:variable> <xsl:variable name=”DisplayTitle”> <xsl:call-template name=”OuterTemplate.GetTitle”> <xsl:with-param name=”Title” select=”@Title”/> <xsl:with-param name=”UrlColumnName” select=”‘LinkUrl'”/> </xsl:call-template> </xsl:variable> <xsl:variable name=”LinkTarget”> <xsl:if test=”@OpenInNewWindow = ‘True'” >_blank</xsl:if> </xsl:variable> <div id=”linkitem” class=”item”> <xsl:if test=”string-length($SafeImageUrl) != 0″> <div class=”image-area-left”> <img class=”image-fixed-width” src=”{$SafeImageUrl}” alt=”{@ImageUrlAltText}”/> </div> </xsl:if> <div class=”link-item”> <xsl:call-template name=”OuterTemplate.CallPresenceStatusIconTemplate”/> <xsl:value-of select=”$DisplayTitle”/> <div class=”description”> <xsl:for-each select=”@*”> <xsl:value-of select=”name()”/> [] <xsl:value-of select=”.”/> [] </xsl:for-each> ContentBody:: <xsl:value-of select=”@ContentBody” /> :: Image:: <xsl:value-of select=”Image” /> :: Comments:: <xsl:value-of select=”Comments” /> :: </div> </div> </div> </xsl:template> I can see the proprety names for my custom filesBut all the values are empty, yet I can see data in list?ResultNews Item AListId [] 4D4B5C29-2DB8-4949-8299-64AC25219CD4 [] WebId [] 0B16AD69-0005-4D91-8B0C-A153C4F8AF0B [] ID [] 1 [] Title [] News Item A [] FileRef [] sites/WebServices/Content/Lists/ContentNewsList/1_.000 [] _x007B_1d22ea11_x002D_1e32_x002D_424e_x002D_89ab_x002D_9fedbadb6ce1_x007D_ [] 1 [] Modified [] 2010-02-11 09:23:25 [] Author [] Walker, Neil (ICT) [] Editor [] Walker, Neil (ICT) [] Created [] 2010-02-09 09:07:43 [] PublishingRollupImage [] [] _Level [] 1 [] Comments [] [] ContentBody [] [] LinkUrl [] http://ldl2865:90/sites/WebServices/Content/Lists/ContentNewsList/1_.000 [] PubDate [] Thu, 11 Feb 2010 09:23:25 GMT [] ImageUrl [] [] ImageUrlAltText [] [] Description [] [] Style [] CustomStyle [] GroupStyle [] DefaultHeader [] __begincolumn [] True [] __begingroup [] False [] file ref:::::sites/WebServices/Content/Lists/ContentNewsList/1_.000 ContentBody:: :: Image:: ::Please help am pulling my hair out.Thanks,Neil..

  133. For those of your struggling with adding attachments, this site explains it nicely :)http://www.wssdemo.com/Lists/Resources/DispForm.aspx?ID=1426&ContentTypeId=0x01005C6956D831EB0B49B4AEE28DF95A05820C00268EA96B67FC8F448ED6072B5D14B7CF

Comments are closed.