title: Restrict user to upload large files
body: <p>Please find my code below. I'm trying to restrict a user to upload file less than 4 MB but I'm getting the content length of 80 MB when I'm selecting a file of 830 KB. <br>
  This code <code>flSignature.PostedFile.ContentLength</code> is not working. Please help.</p>
  
  <p>TIA</p>
  
  <pre><code>string uploadMsg = "";
  string appPath = Server.MapPath("~");
  string parentpath = appPath + "\\app\\Pictures\\";
  //To Upload Multiple Files on Single Click 
  HttpFileCollection hfc = Request.Files;
  for (int i = 0; i &lt; hfc.Count; i++)
  {
      HttpPostedFile hpf = hfc[i];
  
      if (hpf.ContentLength &gt; 0)
      {
          //if (hpf.ContentLength &gt; 4096)
          //{
          //   uploadMsg = "Collective file size is more than 4 MB.";
          //}
          //else
          //{
          if (hfc.AllKeys[i].Contains("flSignature"))
          {
              if (flSignature.PostedFile.ContentLength &gt; 4096)
              { 
                  uploadMsg = "Collective file size is more than 4 MB.";
                  break;
              }
              else
              {
                  if (Path.GetFileName(hpf.FileName).ToLower().Contains("xls") || Path.GetFileName(hpf.FileName).ToLower().Contains("doc"))
                  {
                      showalert("Only Image can be uploaded.");
                  }
                  else
                  {
                      hpf.SaveAs(parentpath + lblUniqueNo.Text + "_signature_" + Path.GetFileName(hpf.FileName));
                  }
              }
          }
          else if (hfc.AllKeys[i].Contains("flPhoto"))
          {
              if (flPhoto.PostedFile.ContentLength &gt; 4096)
              {
                  uploadMsg = "Collective file size is more than 4 MB.";
                  break;
              }
              else
              {
                  if (Path.GetFileName(hpf.FileName).ToLower().Contains("xls") || Path.GetFileName(hpf.FileName).ToLower().Contains("doc"))
                  {
                      showalert("Only Image can be uploaded.");
                  }
                  else
                  {
                      hpf.SaveAs(parentpath + lblUniqueNo.Text + "_passport_" + Path.GetFileName(hpf.FileName));
  
                  }
              }
          }
          else if (hfc.AllKeys[i].Contains("flIdentDoc"))
          {
              if (flIdentDoc.PostedFile.ContentLength &gt; 4096)
              {
                  uploadMsg = "Collective file size is more than 4 MB.";
                  break;
              }
              else
              {
                  hpf.SaveAs(parentpath + lblUniqueNo.Text + "_doc_" + Path.GetFileName(hpf.FileName));
              }
          }
  
  
          //}
      }
  }
  </code></pre>