Whats the best way to check the size of a file during upload using asp.net and C#? I can upload large files by altering my web.config without any problems. My issues arises when a file is uploaded which is more than my allowed max file size.
I have looked into using activex objects but that is not cross browser compatible and not the best answer to the solution. I need it to be cross browser compatible if possible and to support IE6 (i know what you are thinking!! However 80% of my apps users are IE6 and this is not going to change anytime soon unfortunately).
Has any dev out there come across the same problem? And if so how did you solve it?
The filesize() function in PHP is an inbuilt function which is used to return the size of a specified file. The filesize() function accepts the filename as a parameter and returns the size of a file in bytes on success and False on failure.
The id="size" element will be used to display the size of selected file from the id="upload" element. We listen on the change event of the file input, and get the selected files via e. target.
If you are using System.Web.UI.WebControls.FileUpload
control:
MyFileUploadControl.PostedFile.ContentLength;
Returns the size of the posted file, in bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With