Show file size next to file name

3 posts, 1 answers
  1. Vasssek
    Vasssek avatar
    143 posts
    Member since:
    Aug 2010

    Posted 21 Aug 2012 Link to this post

    Hello,

    Could somebody help me ? What I have been trying to do is to show our users not just file name, but also file size information (ContentLength), when file is selected and uploaded...

    It seems that from server side method there are just readonly properties about uploaded files. For example e.File.ContentLength (15423 bytes), etc...

    protected void fileUploaded(object sender, FileUploadedEventArgs e)
    {
       if (RadAsyncUpload1.UploadedFiles.Count > 0)
       {
       }
    }

    Because of this, I suppose, that it should be done from client side, but I don't know how.

    For further information, please check the attachment.

    Please help me to solve this issue.

    Best regards

    Vasssek
  2. Answer
    Bozhidar
    Admin
    Bozhidar avatar
    1103 posts

    Posted 24 Aug 2012 Link to this post

    Hi Vaclav,

    You can use the OnClientFileUploaded event for this purpose. Here's the code for the handler function, that gets the file size and appends it to the row:
    function onClientFileUploaded(sender, args) {
        var fileLength = args.get_fileInfo().ContentLength;
        var spanElement = document.createElement("span");
        spanElement.textContent = fileLength + " bytes";
        args.get_row().appendChild(spanElement);
    }
     
    Kind regards,
    Bozhidar
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vasssek
    Vasssek avatar
    143 posts
    Member since:
    Aug 2010

    Posted 27 Aug 2012 Link to this post

    Hello,

    thank you, It's what I have been looking for :).

    However, I did some little changes in your example. Then the file size is shown immediately after file name and also it has the same CSS formatting:
    ......
    spanElement.textContent = " - " + Math.round(fileLength / 1024) + " KB";
      
    var currentRow = args.get_row();
    currentRow.querySelector(".ruUploadProgress.ruUploadSuccess").appendChild(spanElement);
    ......

    Best regards

    Vasssek

Back to Top