asp.netmulti-upload

How do I load content into Request.Files collection for latter retrieval on server side?


I'm using a multi-upload input control and it is not server sided i.e pure HTML not asp: tagged.

Now the issue is on the server side I'm trying to access the Request object's Files collection hoping that after an upload, the input control will put the files into this collection in question.

I even imported some scripts in javascript to make it work but whenever I step through the code behind, the Request.Files property, which should contain the browsed and chosen files, is always empty. What should I do? Ooooops! sorry i didnt show some code:

var x = this.Page.FindControl("FileUpload1");

            lbuploadmessage.Text = x.GetType().ToString();

          HttpFileCollection hfc = Request.Files; 
            List<L2SQLData.PatientFile> list = new List<L2SQLData.PatientFile>();
            for (int i = 0; i < hfc.Count; i++)
            {
                HttpPostedFile hpf = hfc[i];
                if (hpf.ContentLength > 0 && hpf.ContentLength < 1024000)
                {
                    string filename = Path.GetFileName(hpf.FileName);
                    string ext = Path.GetExtension(hpf.FileName);
                    var guidname = Guid.NewGuid().ToString();
                    //FileUpload1.SaveAs(Server.MapPath("~/Uploads/DocClerkings/") + guidname + ext);

                    hpf.SaveAs(Server.MapPath("~/Uploads/DocClerkings/") + guidname + ext );
                    lbuploadmessage.Text = "Upload status:" + hpf.FileName + " successfully uploaded!";

As you can see I named the control-"FileUpload1" but at runtime (Debug) the object x is null and Request.Files collection that's supposed to contain the browsed files is empty too. The multi - upload control looks like this:

<input id = "FileUpload1" type="file" class="multi"/>

with two scripts i added as follows:

<script src="jquery-latest.js" type="text/javascript" language="javascript"></script>
<script src="jquery.MultiFile.js" type="text/javascript" language="javascript"></script>

So what did I leave out?

Cheers


Solution

  • To make it work you need to change it

    <asp:FileUpload ID="FileUpload1" runat="server" class="multi" />
    

    That plugin is unobstrusive and knows from class="multi" that you want it to do something...

    For a complete walkthrough on how to make it work see http://www.dotnetcurry.com/ShowArticle.aspx?ID=317 and http://www.codeproject.com/KB/aspnet/multiple_file_upload.aspx

    Remark: your usage is not working because this plugin does NOT upload anything, it is "only" for providing some nice additions on the client side - from http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Uploading

    Can this plugin upload files?

    No, this jQuery plugin does not upload files