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

Get file size in javascript for IE

2 Answers 157 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Mansi
Top achievements
Rank 1
Mansi asked on 04 Feb 2011, 09:37 AM
I am using mulitple uploader, and need to get the file size at client side when user selects the file.
Is there any direct method or property to get size?
For now I am using the below code, but it is not working in IE

 function selectedFile(sender, eventArgs) {
   var inputs = sender.getFileInputs();
   for (i = 0; i < inputs.length; i++) {
                    if (navigator.appName == "Netscape") {
                        size = inputs[i].files[0].fileSize;
                    }
               else if (navigator.appName == "Microsoft Internet Explorer") {                  
                        var filepath = inputs[i].value;
                        var SizeINIE = User_book.GetFileSize(filepath);     //This always returns 0 as the file will not be existing on server
                        if (SizeINIE != null) {
                            alert(SizeINIE.value);
                            size = SizeINIE.value;
                        }
                    }
}
Can anyone provide me solution for this ASAP?

2 Answers, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 10 Feb 2011, 01:09 PM
Hi Mansi,

The problem you are experiencing is due to the fact that IE doesn't support this kind of functionality in general.
As you have noticed this is working in Firefox and Chrome but for now there is now way to achieve this functionality with IE.

Kind regards,
Dimitar Terziev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Angel
Top achievements
Rank 1
answered on 01 Jan 2013, 03:35 PM
Actually there is something I`d call a non-solution - it does require you to create a non-secure activeX object:
var filesystem=new ActiveXObject('Scripting.FileSystemObject'),
fullpath=value_of_the_file_input_dom_element;// you know how to get this
var size_bytes=filesystem.getFile(fullpath).size;
M$$ tries to create everything in it`s "own" way. For this to work, you need to select "Initialize and script active x controls not marked safe for scripting" in Security->CustomLevel

A.Genchev
Tags
Upload (Obsolete)
Asked by
Mansi
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Angel
Top achievements
Rank 1
Share this question
or