Home > DeveloperSection > Forums > Adressing a fileupload within a repeater
Simons Hood
Simons Hood

Total Post:70

Posted on    August-25-2014 2:10 AM

 ASP.Net ASP.Net 

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

i have my fileupload within my repeater

  <asp:Content ID="Content3" ContentPlaceHolderID="content" Runat="Server">

<asp:Repeater ID="rptVrijstellingen" runat="server">



        <h2><%# Eval("tblExternVak.ExternvakNaam") %></h2>

        <h4>Selecteer een bestand om te uploaden:</h4>

       Gelieve het bestand de naam te geven van het overeenkomstige vak om de verwerking

           vlot te laten verlopen.

           <br /><br />  <br />

           <asp:FileUpload id="FileUpload1"                



       <br /><br />

       <hr />

       <br />

         <br />

        <asp:Button id="UploadButton"

           Text="Upload file"




       <br />   

    <br />


        <SeparatorTemplate><hr /></SeparatorTemplate>


       <asp:CheckBox id="CBupload" runat="server" />

       <asp:Label id="lblUpload" runat="server"> Geleverd aan Mevrouw Van Orlé</asp:Label>

       <asp:Label id="UploadStatusLabel" runat="server" ForeColor="Red"></asp:Label>  


And i want to adress it from my classfile

   if (FileUpload1.HasFile)




            String fileName = FileUpload1.FileName;

            savePath += fileName;


            tblBijlage s = new tblBijlage();

            s.bijlageTitel = fileName;

            s.bijlageURL = savePath;

            s.bijlageType = "1";

            s.fk_externvakID = 2;

            BLLstudent BLLstudent = new BLLstudent();



        catch (Exception ex)


            UploadStatusLabel.Text = ex.Message;





      UploadStatusLabel.Text = "Gelieve een bestand te kiezen";




The problem is it doesnt find fileupload1 and any other declared stuff within the repeater, can anyone present me a solution on how to adress the upload within the repeater? (I fill up the repeater with data in my page_load so it exists on load so i know that is not the problem)

Thank you in advance 

Sumit Kesarwani

Total Post:378

Posted on    August-25-2014 2:33 AM

Hi Samuel, 

You have to iterate the Items collection of Repeater control and use FindControl method to get the reference of FileUpload1 object.

foreach (RepeaterItem item in rptVrijstellingen.Items)


    FileUpload file=(FileUpload)item.FindControl("FileUpload1");

    String fileName = file.FileName;

    FileUpload1.SaveAs(Server.MapPath(savePath + fileName));


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

Follow MindStick