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.
    http://blogs.microsoft.co.il/blogs/itaysk/archive/2008/02/26/filter-content-query-web-part-by-file-type.aspx

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:choose>
    <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>
    </xsl:choose>
    </xsl:if>
    </xsl:if>
    </xsl:template>
  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” />
    </xsl:call-template>
  7. Select the style you added the file size to in the properties of the CQWP.
    http://blogs.officezealot.com/jrblog/archive/2008/02/21/displaying-file-size-in-a-content-query.aspx

image

Geef een reactie

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

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit / Bijwerken )

Twitter-afbeelding

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

Facebook foto

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

Google+ photo

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

Verbinden met %s