简体   繁体   English

如何使用ASP.Net和Jquery上载多个文件?

[英]How to upload multiple files using ASP.Net and Jquery…?

I have added the following javascripts in my aspx page... 我在aspx页面中添加了以下javascripts ...

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

I have also added the following code in the button click operation. 我还在按钮单击操作中添加了以下代码。

 HttpFileCollection hfc = Request.Files;
    for (int i = 0; i < hfc.Count; i++)
    {
        HttpPostedFile hpf = hfc[i];
        if (hpf.ContentLength > 0)
        {
            hpf.SaveAs(Server.MapPath("MyFiles") + "\\" + System.IO.Path.GetFileName(hpf.FileName));
            Response.Write("<b>File: </b>" + hpf.FileName + " <b>Size:</b> " + hpf.ContentLength + " <b>Type:</b> " + hpf.ContentType + " Uploaded Successfully <br/>");
        }
    }

The problem is I can't select mulltiple files...!!! 问题是我无法选择多重文件... !!!

 <asp:FileUpload id="FileUploadControl" class="multi" runat="server"/>
        <asp:Button ID="BtnUpload" runat="server" onclick="BtnUpload_Click" 
            Text="Upload" Width="105px" style="margin-top: 4px" />
        <asp:Label runat="server" id="StatusLabel" text="Upload status: " />

http://www.c-sharpcorner.com/UploadFile/prathore/multiple-file-upload-using-jquery-in-Asp-Net-3-5/ http://www.c-sharpcorner.com/UploadFile/prathore/multiple-file-upload-using-jquery-in-Asp-Net-3-5/

只是使其倍数

<asp:FileUpload id="FileUploadControl" Multiple="Multiple" class="multi" runat="server"/>

you should use AjaxFileUpload instead of file upload. 您应该使用AjaxFileUpload而不是文件上传。 This is an ajax control toolkit component. 这是一个ajax控件工具包组件。 After that you create the event that will get each file. 之后,您将创建将获取每个文件的事件。 It alredy uploads and give to you the link that the file was uploaded. 它已上传并为您提供了文件已上传的链接。

    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

  <ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1"
    ThrobberID="myThrobber"
    ContextKeys="Vinicius"
    AllowedFileTypes="jpg,jpeg"
    MaximumNumberOfFiles=10
    runat="server"/>

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

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