Friday, August 23, 2013

How to find ASP.NET file upload control file size using javascript ?

The ASP.NET file upload control selected file size can be obtained on javascript. The below code snippet access the fup control object and get the size of the file.

<script type="text/javascript">

        function GetFileSize() {
            alert(document.getElementById("<%=fupUserPhoto.ClientID%>").files[0].size);
        }

</script>

<div>
            <asp:FileUpload ID="fupUserPhoto" runat="server" />
            <br />
            <input type="button" id="btnGetSize" value="Get file size" onclick="GetFileSize()" />
</div>

The size of the file will be returned in byte.

4 comments: