Webforms Upload multiple files

0

I have a WebForms application that needs to receive multiple files that will be associated with a specific type of my system.

Ex:

Type : [Driver's license] | File : img001.png
Type : [Proof of residence] | File : comp001.pdf

I need to receive this information on a page WebForm .aspx .

If it was just to get the files, you could pick it up using Request.Files , however you need to know the Type of the document to be able to save to the bank.

I've figured out how to use the name of the file fields as a array using arquivos[0] , arquivos[1] and associate with type ( tipos[0] , tipos[1] ). Doing so could use the indexes that I could guarantee the type would be related to the file. But I do not know how to access this information on .aspx pages.

With MVC I can do this well, but since I do not have the domain with WebForms , I end up beating myself up a bit.

How could I do this in a way without "Gambiarras"?

    
asked by anonymous 05.01.2016 / 20:13

1 answer

0

Just user multiple components of type asp:FileUpload and access them using their respective name in the desired event following the example below;

<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="false"/>
<asp:FileUpload ID="FileUpload2" runat="server" AllowMultiple="false"/>
protected void btnUpload_Click(object sender, EventArgs e)
{
    if(FileUpload1.HasFile)
    {
        var file1info = FileUpload1.FileName + " - " + FileUpload1.PostedFile.ContentLength + " Bytes.";
        //logica para salvar
    }

    if(FileUpload2.HasFile)
    {
        var file2info = FileUpload2.FileName + " - " + FileUpload2.PostedFile.ContentLength + " Bytes.";
        //logica para salvar
    }
}
    
05.01.2016 / 21:02