This is a migrated thread and some comments may be shown as answers.
Show file size next to file name
2 Answers 38 Views
This is a migrated thread and some comments may be shown as answers.
Vasssek
Top achievements
Rank 1
Vasssek asked on 21 Aug 2012, 12:40 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Bozhidar
Telerik team
answered on 24 Aug 2012, 10:07 AM
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.
0
Vasssek
Top achievements
Rank 1
answered on 27 Aug 2012, 05:54 AM
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

Asked by
Vasssek
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Vasssek
Top achievements
Rank 1
Share this question
or