FILEUPLOAD UPLOAD CODEBEHIND.

marcel ethan

Total Post:104

Points:728
Posted by  marcel ethan
 1165  View(s)
Ratings:
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.

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: FileUpload upload codebehind.

    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)
     }

      Modified On Apr-05-2018 04:43:23 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!