3

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.

2 Answers 2

7

(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));
    }
}   
Sign up to request clarification or add additional context in comments.

Comments

1

HttpFileCollection uploads = HttpContext.Current.Request.Files;

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

        HttpPostedFile upload = (HttpPostedFile)uploads[i];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.