Filter The Content Query Web Part by file type and display file size.

Today I had to configure a Content Query WebPart to display the most recent modified documents and their file size. An easy task which I had quickly completed by reading two blogposts:

Filter CQWP by File Type:

  1. Insert a CQWP to a page and configure it as you would like.
  2. Export the web part and save it as “.webpart” file on your local computer.
  3. Open the “.webpart” file in a text editor. (I use SharePoint Designer)
  4. Look for the following line:
    <property name="CommonViewFields" type="string" />
  5. Replace it with the following line:
    <property name="CommonViewFields" type="string">DocIcon,Lookup</property>
    This will make the CQWP retrieve also the DocIcon field that basically include the file extention.
  6. Look for the following line:
    <property name="AdditionalFilterFields" type="Lookup" null="true" />
  7. Replace it with the following line:
    <property name="AdditionalFilterFields" type="Lookup" >DocIcon</property>
    This will make our CQWP to allow you to filter by our newly added DocIcon field through the filtering UI in the web part’s toolpane.
  8. Save the file.
  9. Go to a sharepoint page and import the modified “.webpart” file into your page.

CQWP Filter Before and After

Display File Size:

  1. Export the .webpart file for the content query you want to have the file size.
  2. Change the CommonViewFields property in the .webpart file to look like the following:
    <property name=”CommonViewFields” type=”string”>FileSizeDisplay,Computed;File_x0020_Size,Lookup;</property>
  3. Save the .webpart file
  4. Import the .webpart file and put it on a page
  5. Add the following to the end of the itemstyle.xsl:
    <!– The size attribute for each item is prepared here –>
    <xsl:template name=”DisplaySize”>
    <xsl:param name=”size” />
    <xsl:if test=’string-length(@FileSizeDisplay) &gt; 0′>
    <xsl:if test=”number(@FileSizeDisplay) &gt; 0″>
    <xsl:when test=”round(@FileSizeDisplay div 1024) &lt; 1″><xsl:value-of select=”@FileSizeDisplay” /> Bytes</xsl:when>
    <xsl:when test=”round(@FileSizeDisplay div (1024 *1024)) &lt; 1″><xsl:value-of select=”round(@FileSizeDisplay div 1024)” />KB</xsl:when>
    <xsl:otherwise><xsl:value-of select=”round(@FileSizeDisplay div (1024 * 1024))”/>MB</xsl:otherwise>
  6. Create a new style in the itemstyle.xsl and include the following where you want the file size to appear:
    <xsl:call-template name=”DisplaySize”>
    <xsl:with-param name=”size” select=”size” />
  7. Select the style you added the file size to in the properties of the CQWP.



Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen. logo

Je reageert onder je account. Log uit /  Bijwerken )

Google+ photo

Je reageert onder je Google+ account. Log uit /  Bijwerken )


Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )


Verbinden met %s