Click here to Skip to main content
16,016,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I am using the file upload in my site, i want to upload file only below of 1 MB.
I want to check the size of file in IE Browser using javascript then how it would be possible pls reply me.
I am using following javascript->

C#
function CheckFileSize() {
   var file = document.getElementById('<%=UplPicture.ClientID%>');

C#
if (file.files[0].size >= 1048576) {
                        alert('File size should be less than or Equal to 1 MB');
                        return false;
                    }
else
return true;
}



It works fine in firefox but not working in IE.
Posted

1 solution

Try:
HTML
<head>
<script>
function GetFileSize()
{
   var myFSO = new ActiveXObject("Scripting.FileSystemObject");
   var filepath = document.upload.file.value;
   var selectedfile = myFSO.getFile(filepath);
   var size = selectedfile.size;
   alert("File size:"+ size + " bytes");
}
</script>
</head>
<body>
<form name="TestUpload">
<input type="file" name="file">
<input type="button" value="Size" onClick="GetFileSize();">
</form>
</body>
</html>
 
Share this answer
 
Comments
nira.parmar 27-Jun-12 14:12pm    
tried but not working
Sandeep Mewara 27-Jun-12 14:27pm    
I see similar thing used by others and they too say working: http://www.kavoir.com/2009/01/check-for-file-size-with-javascript-before-uploading.html
Espen Harlinn 27-Jun-12 19:10pm    
5'ed!

Tools -> Internet Options -> Security -> Custom Level

In the ActiveX controls and Plugins group enable the Initialize and script Activex controls not marked as safe for script option
Sandeep Mewara 28-Jun-12 9:02am    
Perfect! thanks man.
nira.parmar 29-Jun-12 1:49am    
Pls give me the effective solution...............

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900