Steve Davies
Steve Davies

Reputation: 562

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.

Upvotes: 3

Views: 11017

Answers (2)

soe
soe

Reputation: 11

HttpFileCollection uploads = HttpContext.Current.Request.Files;

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

        HttpPostedFile upload = (HttpPostedFile)uploads[i];

Upvotes: 1

Steve Davies
Steve Davies

Reputation: 562

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

Upvotes: 7

Related Questions