0

I'm using a asp.net file uploader control, but whem the user select the file twice, the first selecion is reseted. For example: I select 3 files, before click the Upload button, I click on "Browse" again again, and select two more. Than I click on the Upload button. If I call Resquest.Files, i will get only the last two files. I need to get all the 5 files.

WebForm1.aspx: http://pastebin.com/kkpUA3dr

WebForm1.aspx.cs: http://pastebin.com/N9ahyU8c

user2013107
  • 265
  • 1
  • 4
  • 12
  • Sounds like it is working as intended. Are you posting back prior to changing the selected files? – Frazell Thomas Feb 24 '13 at 03:04
  • What i want is: if the user select two files and before click on the upload button select three more i want to have all the 5 files, got it? – user2013107 Feb 24 '13 at 03:09

3 Answers3

1

I am not sure what do you want to achieve, but I think that is expected. I guess if you select the files multiple times using the upload file control , the control only keep the last selection that is the default behavior.

Stay Foolish
  • 3,636
  • 3
  • 26
  • 30
0

Then you need multiple file uploader

0

asp:FileUpload is not support you to do that. In this case, you can use other library for upload multiple files. HTML:

<html >
<head runat="server">
    <title>Multiple file Upload</title>
    <script src="http://jquery-multifile-plugin.googlecode.com/svn/trunk/jquery.js" 
    type="text/javascript"></script>
    <script src="http://jquery-multifile-plugin.googlecode.com/svn/trunk/jquery.MultiFile.js" 
    type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:FileUpload ID="FileUploadJquery" runat="server" 
        class="multi" accept="jpg|png" />
    
    </div>
    </form>
</body>
</html>

C# code to handle fileupload control:

string fileName1 = "";
string FullName1 = "";
HttpFileCollection uploads = Request.Files;
//for (int fileCount = 0; fileCount < uploads.Count; fileCount++)
for (int fileCount = 1; fileCount < 6; fileCount++)
{
    if (fileCount < uploads.Count)
    {
        HttpPostedFile uploadedFile = uploads[fileCount];
        fileName1 = Path.GetFileName(uploadedFile.FileName);
        if (uploadedFile.ContentLength > 0)
        {
            string[] a = new string[1];
            a = uploadedFile.FileName.Split('.');
            fileName1 = a.GetValue(0).ToString() + 
            "." + a.GetValue(1).ToString();
            uploadedFile.SaveAs(Server.MapPath
            ("mobile_image/mob_img/" + fileName1));
        }
} 

Source: http://www.codeproject.com/Tips/531692/Multiple-File-Upload-Using-jQuery

nguyenhoai890
  • 1,189
  • 15
  • 20