2013-02-24 58 views
0

我正在使用一个asp.net文件上传程序控件,但是当用户选择文件两次,第一个selecion被重置。例如:我选择3个文件,在点击上传按钮之前,我再次点击“浏览”,然后再选择两个文件。比我点击上传按钮。如果我打电话Resquest.Files,我只会得到最后两个文件。我需要获得所有5个文件。多文件上传重置Request.Files

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

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

+0

听起来像在按预期运行。您是否要在更改选定文件之前回传? – 2013-02-24 03:04:48

+0

我想要的是:如果用户选择两个文件,并在点击上传按钮之前选择另外三个我想拥有所有5个文件,明白了吗? – user2013107 2013-02-24 03:09:51

回答

1

我不知道你想达到什么样的,但我认为预期。我猜如果你使用上传文件控制多次选择这些文件,控件只会保留最后一个选择是默认行为。

+0

是的,这就是我所说的,有什么办法可以保留所有的选择? – user2013107 2013-02-24 03:12:32

0

然后,你需要多文件上传

+0

我正在使用这个,看代码。 – user2013107 2013-02-24 04:55:54

0

asp:FileUpload不支持你这样做。在这种情况下,您可以使用其他库来上传多个文件。 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#代码来处理文件上传控制:

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)); 
     } 
} 

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