Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Douglas Robar 3570 posts 4670 karma points MVP 6x admin c-trib
    Aug 14, 2009 @ 16:48
    Douglas Robar

    Multiple upload controls on a docType... can I get file sizes?

    I just realized that the upload datatype doesn't store umbracoBytes, which means I have no way of getting and displaying the size of the uploaded file. All I have is the url to the file.

    I could add a label (aka, static text) property to my docType called 'umbracoBytes' and it would be auto-populated (and this is VERY cool!) but... I've got four upload fields and whatever item is uploaded last will put its filesize in the 'umbracoBytes' field. I need to know the size of each of the uploads.

    I don't want to resort to forcing the users to upload the four files to the media section by hand (even with zip upload), and then have to go back to the content area and select each of those files with a media picker. The files aren't re-used so the simplicity of uploading directly from the docType is fantastic. I just need to get the filesize from each of the upload fields.

    Any ideas?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 14, 2009 @ 16:57
    Thomas Höhler

    Write an xslt extension getting the bytes:

    System.IO.FileInfo fi = new FileInfo(PathToFile);
    return fi.Length;


  • Dirk De Grave 4534 posts 5981 karma points MVP 3x admin c-trib
    Aug 14, 2009 @ 21:08
    Dirk De Grave

    Or, if you'd like to avoid the calls in xslt, register for save events on documents, check doc type and set a read-only property (label) with filesize of upload -> bit of a hack, but all work is done in backend and can be retrieved in xslt quite fast.

    If you don't like to show the bytes field on the doc type, think @ismayat has done some work on hiding properties from a user (think it was done in jquery talk)


    Might be quite some overhead tho...




  • Chris Koiak 700 posts 2626 karma points
    Aug 14, 2009 @ 21:35
    Chris Koiak

    Thinking about Dirks suggestion....

    Maybe your event handler just checks if there are any properties of type Upload and then appends "_umbracoBytes" and updates the properties accordingly.

    Therefore if your upload control was called 'ImageFile' the event handler would set 'ImageFile_umbracoBytes' to the filesize property.

    This should then make the solution quite flexible.

    I think it's better to do this check once and cache the values than check the filesize every page load.

  • Douglas Robar 3570 posts 4670 karma points MVP 6x admin c-trib
    Aug 17, 2009 @ 09:15
    Douglas Robar

    Thanks, guys! I was pulling my hair out on this one and you all presented the voice of sanity and good advice when I needed. Thanks!

    I'm marking Thomas' answer as the solution because it is the one I used on the site. It was quick and easy to implement, right inside my xslt macro. Performance is very good and I'll be caching this macro heavily as well.

    If performance does ever become an issue I'll create an event handler to write the upload size for each control as Dirk and Chris suggested, as that will maximize performance.

    Here's the relevant bits of the xslt macro for reference:

    <xsl:template name="downloadSize">
        <xsl:param name="productVersionNode" />
        <xsl:variable name="filePath">
                <xsl:when test="string(data[@alias='uploadStandard']) != ''">
                    <xsl:value-of select="data[@alias='uploadStandard']" />
                <xsl:when test="string(data[@alias='uploadPortable']) != ''">
                    <xsl:value-of select="data[@alias='uploadPortable']" />
                <xsl:when test="string(data[@alias='uploadPortableU3']) != ''">
                    <xsl:value-of select="data[@alias='uploadPortableU3']" />
                <xsl:when test="string(data[@alias='uploadSlim']) != ''">
                    <xsl:value-of select="data[@alias='uploadSlim']" />

        <xsl:if test="string($filePath) != '' ">
            <xsl:value-of select="ps:uploadFileSize($filePath)" />
            <xsl:text> kb)</xsl:text>

    <!-- =========================================================== -->

    <msxml:script language="CSharp" implements-prefix="ps">
        <msxml:using namespace="System.IO" />
        <msxml:assembly name="System.Web" />
        <msxml:using namespace="System.Web" />

        public String uploadFileSize(String filePath) {

            if ((filePath != null) && (filePath.Length != 0)) {
                String localFile = HttpContext.Current.Server.MapPath(filePath);
                if (File.Exists(localFile)) {
                    FileInfo fileinfo = new FileInfo(localFile);
                    return (fileinfo.Length / 1024).ToString();
            return null;

    <!-- =========================================================== -->


  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Aug 17, 2009 @ 09:45
    Casey Neehouse

    I agree that I would like to see the file upload data type store the extra details inside the single data element, rather than across several others.

    IE, use xml to save all the properties, various thumbs, etc. 

    Thought, Doug, I like your approach! :P

  • Jeffrey Valeroso 40 posts 101 karma points
    Mar 10, 2012 @ 02:45
    Jeffrey Valeroso

    You may want to use my multiple file uploader

    Download it here.


Please Sign in or register to post replies

Write your reply to: