0

How to measure file size using jquery,the following code works fine in firefox,chrome but it is not work in IE (7/8/9). Can any one help me how to measure file size in IE

var fi = document.getElementById('loadfile');
var sizeInMB = fi.files[0].size;
    sizeInMB = (sizeInMB / (1024 * 1024));
if (sizeInMB > 20)
    alert("File size more than 20MB");
else
    alert("File size less than 20MB");
abatishchev
  • 95,331
  • 80
  • 293
  • 426
user973063
  • 31
  • 2
  • 8

1 Answers1

0

Try this way:

<script runat="server">

    protected void UploadButton_Click(object sender, EventArgs e)
    {

        string savePath = @"c:\temp\uploads\";


        if (FileUpload1.HasFile)
        {                
            // Get the size in bytes of the file to upload.
            int fileSize = FileUpload1.PostedFile.ContentLength;

            // Allow only files less than 2,100,000 bytes (approximately 2 MB) to be uploaded.
            if (fileSize < 2100000)
            {

                // Append the name of the uploaded file to the path.
                savePath += Server.HtmlEncode(FileUpload1.FileName);


                FileUpload1.SaveAs(savePath);


                UploadStatusLabel.Text = "Your file was uploaded successfully.";
            }
            else
            {

                UploadStatusLabel.Text = "Your file was not uploaded because " + 
                                         "it exceeds the 2 MB size limit.";
            }
        }   
        else
        {

            UploadStatusLabel.Text = "You did not specify a file to upload.";
        }
    }
</script>
coder
  • 14,892
  • 32
  • 111
  • 215