Avatar of coastman14
 asked on

c# syntax Loop through request.files Item...

                                                 foreach (string item in Request.Files)
                  if (System.Web.UI.WebControls.[item].PostedFile.ContentLength <= 250000)
                                                                                                                   The type or namespace name 'item' does not exist in the class or namespace 'System.Web.UI.WebControls' (are you missing an assembly reference?)

 I am creating the Files in a placeholder and they do not have static names, what syntax do i use, for the simple example above...


Avatar of undefined
Last Comment
Ravi Singh

8/22/2022 - Mon
Jaime Olivares

maybe you can post where item is declared
Ravi Singh

Hi, you have a period before the indexer, try changing your condition to:

if (System.Web.UI.WebControls[item].PostedFile.ContentLength <= 250000)
Ravi Singh

Sorry ignore my previous post, it wouldn't correct the issue
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.

     private void cmdUpload_ServerClick(object sender, System.EventArgs e)
                  string filenumber="";
                  string formvalue="";
                  string mysql=" update lee2 set ";
                  //foreach ( DataRow row in table.Rows )
                  foreach (string item in Request.Files)
                  //Go and get the files that are not null
                  if (( Request.Files[item] != null) && (Request.Files[item].ContentLength>0))
                  string sFileName = System.IO.Path.GetFileName(Request.Files[item].FileName);
                  //Response.Write (sFileName);
                  //Response.Write (item.ToString());            
                  formvalue=(Request.Form["textbox" + filenumber]);
                        if (formvalue!="" && formvalue!=" " && formvalue!=null && Request.Form["textbox" + filenumber]!="" && System.Web.UI.WebControls.[item].PostedFile.ContentLength <= 250000)
Jaime Olivares

In fact Zephyr's comment is interesting, there is a strage dot after WebControls...
Ravi Singh

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question