Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net Upload of multiple files after choosing them from jQuery

I have used a jQuery multiple file upload control [ MultiFile from fyneworks http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Overview ] to collect some filenames but can't work out how to upload them on the server.

The standard asp:FileUpload control only seems to allow single files and I don't want to use the swfupload control, just plain old aspx.

like image 884
Steve Davies Avatar asked Nov 27 '25 22:11

Steve Davies


2 Answers

(I have answered this question myself, I just had problems finding the answer via goole or SO and it seems useful ...)

This code works for what I need, thanks to Suprotim Agarwal http://www.dotnetcurry.com/ShowArticle.aspx?ID=68

Once the files have been chosen using a suitable jQuery multiple upload control (eg MultiFile from fyneworks http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Overview) and the submit button has been clicked, call the following code in the aspx file

HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
    HttpPostedFile hpf = hfc[i];
    if (hpf.ContentLength > 0)
    {               
        hpf.SaveAs(Server.MapPath("Uploads") + "\\" + System.IO.Path.GetFileName(hpf.FileName));
    }
}   
like image 194
Steve Davies Avatar answered Nov 30 '25 12:11

Steve Davies


HttpFileCollection uploads = HttpContext.Current.Request.Files;

for (int i = 0; i < uploads.Count; i++) {

        HttpPostedFile upload = (HttpPostedFile)uploads[i];
like image 35
soe Avatar answered Nov 30 '25 11:11

soe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!