Display File Size of documents (pdf,word, excel) on a Page
HI,
I need to display file size of a document in a website. In my website, the content section contains the pages.
Can we create an Xslt and call it in the content section (particular page)?
OR
I had created a dll file which included the function of getfilze in c#. I could call that fucntion in the Template master but could call it on Content pages. How can call the fuction on Content pages?
The size of media items is stored in the XML cache, along with file name, extension and a bunch of other properties. You can get it by doing something like this:
When you create your XSLT file, make sure 'create macro' is selected. This will create a macro which will run your XSLT file from wherever you call that macro.
To embed the macro into your content, you have several options. The most common way to do it is to embed it into the template directly. So in the template file, just click the 'embed macro' button from the tool-bar and select the macro from the list of available macros.
Another common way to do it would be to let the user embed the macro into a rich text editor, but that can be a bit ugly sometimes.
It's been a while since I watched them but I highly recommend spending an hour or two watching the Umbraco TV tutorials. There are a couple on macros which I'm sure will explain this a lot better than me:
Display File Size of documents (pdf,word, excel) on a Page
HI,
I need to display file size of a document in a website. In my website, the content section contains the pages.
Can we create an Xslt and call it in the content section (particular page)?
OR
I had created a dll file which included the function of getfilze in c#. I could call that fucntion in the Template master but could call it on Content pages. How can call the fuction on Content pages?
Note: Either options would be appreciated.
Thanks.
Hi,
The size of media items is stored in the XML cache, along with file name, extension and a bunch of other properties. You can get it by doing something like this:
<xsl:template match="/">
<xsl:variable name="mediaId" select="number($currentPage/mediaId)" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="$mediaNode/umbracoFile">
File size in bytes: <xslt: value-of select="$mediaNode/umbracoBytes" />
</xsl:if>
</xsl:if>
</xsl:template>
So no need for any .NET - it can all be done simply with XSLT (that is if you're using Umbraco < 5 )
Hi Dan,
After creating the xslt, how can we call it on content section?
It would be great if you could provide us with an example.
Thanks.
When you create your XSLT file, make sure 'create macro' is selected. This will create a macro which will run your XSLT file from wherever you call that macro.
To embed the macro into your content, you have several options. The most common way to do it is to embed it into the template directly. So in the template file, just click the 'embed macro' button from the tool-bar and select the macro from the list of available macros.
Another common way to do it would be to let the user embed the macro into a rich text editor, but that can be a bit ugly sometimes.
It's been a while since I watched them but I highly recommend spending an hour or two watching the Umbraco TV tutorials. There are a couple on macros which I'm sure will explain this a lot better than me:
http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/sitebuilder-introduction/what-are-macros/TVPlayer
http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/sitebuilder-introduction/creating-your-first-xslt-macro/TVPlayer
Hope this helps...
is working on a reply...