0

Is there a way I can display a message box saying that the file uploaded is greater than 4 MB. the following code in the code behind cs file does not work

   if (FileUploader.PostedFile.ContentType == "application/pdf" && FileUploader.PostedFile.ContentLength < 4000000)
            {
Ben
  • 51,770
  • 36
  • 127
  • 149
Shomaail
  • 493
  • 9
  • 30
  • looks like you have correct checking "ContentLength < 4000000". If you're doctype checking fails this wouldn't work because you have "&&" not OR – unixmiah Oct 21 '14 at 13:09
  • when the file is more than 4MB it does not reaches here and routes to the error page. i can remove the pdf restriction but it does not answer my question. – Shomaail Oct 22 '14 at 05:05

1 Answers1

2

I was able to solve the problem by adding this is to the web.config. No changes to the IIS is made

 <system.web>
     <httpRuntime maxRequestLength="102400" />

this allowed the following code to execute and the message is displayed successfully

if (FileUploader.PostedFile.ContentType == "application/pdf" &&      FileUploader.PostedFile.ContentLength < 4000000)
  {   ...   }
else 
  {
labelProgrammaticPopup3.Text = "You can only upload valid PDF files of size less than 4 MB.";                    
this.programmaticModalPopup3.Show();
 }
Shomaail
  • 493
  • 9
  • 30