I am using ASP.net with VB.NET. Is there some Validator that I can use that will check the size of the uploaded image? Else what must I do in code to make sure that the user do not upload images more than 1MB?
p.s C# code will also do, I can use a converter to VB.NET
EDIT
For some reason when I change the maxRequestLength to 1024 (in my WEB.config) and I upload a image with size 1.25mb then I get the Microsoft Error page saying "Internet Explorer cannot display the webpage". And I do have a Try Catch block inside my Submit button. If I remove the maxRequestLength from my Web.config then it works fine.
This is ultimately handled in Web.config. Look for the httpRuntime section:
<httpRuntime
executionTimeout="110"
maxRequestLength="4096"
/>
There are many other settings in httpRuntime but these are the two that are relevant. Here, the maxRequestLength is set to 4096, or 4KB (the number is in bytes). So, set this value accordingly. Also, you will want to set the executionTimeout accordingly as well so it gives a reasonable amount of time to upload whatever you max upload is.
You can use the following code to determine the size [in KB] of the uploaded file and once you know the size you can easily decide if you want to proceed further with the file or reject the upload.
Request.Files(0).ContentLength / 1024
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