views:

3903

answers:

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

(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));
    }
}
Steve Davies
thanks, this is exactly what I am looking for
sean717
A: 

I have problems with that code in this line

HttpFileCollection hfc = Request.Files;

on Request.Files says: Cannot implicitly convert type 'System.Collections.IDictionary' to 'System.Web.HttpFileCollection'

Do you know how can i solve this issue??

thanx in advance

Mau
A: 

HttpFileCollection uploads = HttpContext.Current.Request.Files;

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

        HttpPostedFile upload = (HttpPostedFile)uploads[i];
soe