View Single Post
  #1 (permalink)  
Old April 11th, 2012, 10:30 PM
malie22001 malie22001 is offline
Authorized User
Points: 194, Level: 3
Points: 194, Level: 3 Points: 194, Level: 3 Points: 194, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default 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!


PS: In know this problem might not be directly related to the book; however, the book mentioned using the FileUpload control within the DetailsView control to upload a file. I am following the same technique, but just need a way to prevent the user from uploading a huge file. I try doing this with the FileUpload control outside of the DetailsView control's ItemInserting event and it works, but within, it doesn't work...
Reply With Quote