Welcome to Office Zealot Sign in | Join | Help

John Roe

SharePoint
Displaying File Size in a Content Query
I was asked recently how to display the file size in a content query. After a bit of digging I was able to find the appropriate field names and use some xsl from the search results to properly format and display the file size.
 
Note: If you're not familar with Customizing the content query webpart Heather Solomon has an excellent post that you may want to review here: http://www.heathersolomon.com/blog/articles/customitemstyle.aspx
 
Here's how to do it:
 
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 CQ webpart
Posted: Thursday, February 21, 2008 3:12 PM by John

Comments

No Comments

Anonymous comments are disabled