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

Total Post:70

Points:494
Posted on    August-25-2014 2:10 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 992  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">

        <HeaderTemplate></HeaderTemplate>

        <ItemTemplate>

        <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"                

           runat="server">

           </asp:FileUpload>

       <br /><br />

       <hr />

       <br />

         <br />

        <asp:Button id="UploadButton"

           Text="Upload file"

           OnClick="UploadButton_Click"

           runat="server">

       </asp:Button>    

       <br />   

    <br />

            </ItemTemplate>

        <SeparatorTemplate><hr /></SeparatorTemplate>

        </asp:Repeater>   

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

</asp:Content>

And i want to adress it from my classfile

   if (FileUpload1.HasFile)

    {

        try

        {

            String fileName = FileUpload1.FileName;

            savePath += fileName;

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

            tblBijlage s = new tblBijlage();

            s.bijlageTitel = fileName;

            s.bijlageURL = savePath;

            s.bijlageType = "1";

            s.fk_externvakID = 2;

            BLLstudent BLLstudent = new BLLstudent();

            BLLstudent.insertFile(s);

        }

        catch (Exception ex)

        {

            UploadStatusLabel.Text = ex.Message;

        }

    }

    else

    {

      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

Points:2694
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