Validating the size of a file being uploaded by the FileUpload control
Hi guys,
I have a little problem I'm struggling with here. I have a DetailsView control, which I have converted into templates and replaced some of its fields with regular server controls. One of such controls is the FileUpload control.
I want the user to be able to upload an image that will serve as a product avatar. The problem is, I need to make sure that the image being uploaded is not bigger than 2MB.
I am tapping into the DetailsView control's ItemInserting Event to get the file info from the FileUpload control and do a test on the size of the file before assing the e.Values property a file URL.
The problem is that the run time seems to be ignoring my chek for file size and going straight through the rest of the code.
The file size limit of the FileUpload control is determined by the httpRunTime element in the web.config file. I have set this element to accept only a file of size 2MB. However, I want a nice way to let the user know that they are trying to upload a large file.
So far, I am not getting any luck, my code is just being ignored and IE is displaying an unfriendly error message.
Can anyone help me out?
Thanks guys; you are the best!
|