简体   繁体   English

多个文件上载会重置Request.Files

[英]Multiple File Upload resets Request.Files

I'm using a asp.net file uploader control, but whem the user select the file twice, the first selecion is reseted. 我正在使用asp.net文件上载器控件,但是当用户两次选择文件时,第一个选择被重置。 For example: I select 3 files, before click the Upload button, I click on "Browse" again again, and select two more. 例如:我选择3个文件,然后单击“上传”按钮,然后再次单击“浏览”,然后再选择两个。 Than I click on the Upload button. 比我点击上传按钮。 If I call Resquest.Files, i will get only the last two files. 如果我调用Resquest.Files,我只会得到最后两个文件。 I need to get all the 5 files. 我需要获取所有5个文件。

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

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

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. 我想如果您使用上载文件控件多次选择文件,则该控件仅保留最后的选择,这是默认行为。

然后,您需要多个文件上传器

asp:FileUpload is not support you to do that. asp:FileUpload不支持您这样做。 In this case, you can use other library for upload multiple files. 在这种情况下,您可以使用其他库上载多个文件。 HTML: 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: 用于处理文件上传控制的C#代码:

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 资料来源: http : //www.codeproject.com/Tips/531692/Multiple-File-Upload-Using-jQuery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM