0

I want to restrict users from uploading file sizes of more than 4MB, is there any way to do this without modifying the configuration file? I tried the code below to validate the file and response redirect but was still not able to make it. As long as I upload a file that is larger than 4MB it crashes when I click submit.

if(FileUpload1.PostedFile.ContentLength > 1234)
{
    FileUpload1.Attributes.Clear();
    Response.Redirect("Main.aspx");
}
Rahul Sharma
  • 7,768
  • 2
  • 28
  • 54
pikabob
  • 21
  • 4
  • Does this answer your question? [How to increase the max upload file size in ASP.NET?](https://stackoverflow.com/questions/288612/how-to-increase-the-max-upload-file-size-in-asp-net) – phuzi Mar 14 '22 at 09:30
  • nope, I was trying to not touch configuration file . – pikabob Mar 14 '22 at 09:35

0 Answers0