0

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

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

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

4

3 回答 3

1

我不确定你想达到什么目标,但我认为这是意料之中的。我猜如果您使用上传文件控件多次选择文件,该控件只会保留最后一次选择,即默认行为。

于 2013-02-24T03:07:29.443 回答
0

然后你需要多个文件上传器

于 2013-02-24T04:51:06.007 回答
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

于 2016-05-05T07:45:01.023 回答