This is a migrated thread and some comments may be shown as answers.

Accessing uploaded file size?

1 Answer 79 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Charles
Top achievements
Rank 1
Charles asked on 14 Feb 2009, 12:39 AM
Hi,

I noticed in the silverlight upload control that when a file is selected on the client, the file size displays in the control.

Is it possible to obtain the length of the file in bytes in the upload handler as its being uploaded? Is it in some dictionary object ?

Thanks

1 Answer, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 16 Feb 2009, 04:11 PM
Hi Charles,

Thank you for contacting Telerik Support.

We verified that the file size is not sent to the upload handler. We consider this to be a valuable addition and will update the RadUpload to do support it.

Currently, you can work the issue around by using a custom parameter to send the file size value. To accomplish this task you should follow the following two steps:

1. Add the FileUploadStarting event handler (for RadUpload control) where the custom parameter (with the value of the file size) will be supplied:

public partial class Page : UserControl 
   ... 
   private void RadUpload_FileUploadStarting(object sender, 
         Telerik.Windows.Controls.FileUploadStartingEventArgs e) 
   { 
      e.FileParameters.Add("customTag_FileSize"
            this.radUpload.CurrentSession.CurrentFile.Size); 
   } 
   ... 

2. Override the ProccessStream method (in the upload handler) and process the custom parameter:

public class MyRadUploadHandler : Telerik.Windows.RadUploadHandler 
   public override void ProcessStream() 
   { 
      string sFileSize = this.Request.Form["customTag_FileSize"]; 
      if (sFileSize != null
      { 
         long fileSize = 0; 
         if (long.TryParse(sFileSize, out fileSize)) 
         { 
            // here we can rely on the value in fileSize. 
         } 
      } 
      base.ProcessStream(); 
   } 

Please give it a try and let me know if there are more questions.

Sincerely yours,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Upload
Asked by
Charles
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Share this question
or