Home > DeveloperSection > Forums > FileUpload upload codebehind.
marcel ethan
marcel ethan

Total Post:105

Points:735
Posted on    August-28-2014 1:47 AM

 ASP.Net
Ratings:


 1 Reply(s)
 707  View(s)
Rate this:

        private void SetChildrenCountControls(int total)

        {

          for (int i = 0; i < total; i++)

          {

            var tbBirthDate = new TextBox();

            tbBirthDate.ID = "tbBirthDate_" + (i + 1);

            tbBirthDate.CssClass = "tbSister_input";

            tbBirthDate.EnableViewState = true;

 

            FileUpload upload = new FileUpload();

            upload.ID = "imgUpload_" + (i + 1);

            upload.CssClass = "tbSister_upload";

            upload.EnableViewState = true;

 

            ChildrenCountTextPanel.Controls.Add(tbBirthDate);

            ChildrenCountTextPanel.Controls.Add(upload);

          }

       }   

And can get the enterede text in the txtbox with:

 

         protected void lbFamilySave_Click(object sender, EventArgs e)

    {

        var countSisters = ChildrenCountTextPanel.Controls.OfType<TextBox>();

        string sisterBirth = string.Empty;

        foreach (var sister in countSisters)

        {

            if (sister.ID.Contains("tbBirthDate_"))

                sisterBirth = sister.Text;

        }

    }

How can i get the file from the FileUpload controls? Cant seem to do above with FileUpload.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-28-2014 2:38 AM

Hi marcel, 

Got it working with this, thought i had tryed that. Apparently not good enough :)

 var countUploads = ChildrenCountTextPanel.Controls.OfType<FileUpload>();

        FileUpload FileUl = new FileUpload();

        foreach (var ul in countUploads)

        {

            if(ul.ID.Contains("imgUpload_"))

            {

                FileUl = ul;              

            }

        }

if (FileUl.HasFile)

{

 ConvertAndSave(FileUl)

 }


Don't want to miss updates? Please click the below button!

Follow MindStick