![](/img/trans.png)
[英]How to open local files by button click and upload multiple files and display like gmail feature to delete
[英]Upload multiple files with One Button Click
這個元素,
<asp:FileUpload ID="FileUploadEventosCasal" runat="server" />
可以按時間上傳一個文件(單擊按鈕)。
我想知道如何一鍵上傳多個文件(排隊)。 我不能使用.net 4.5。 我想要類似以下示例的內容: http : //www.aspdotnet-suresh.com/2012/12/aspnet-upload-multiple-files-using.html為了使其工作,我進行了以下更改:
<script src="js/jquery-1.8.2.js"></script>
<script>$(function () {/* jquery.MultiFile.js code pasted here */});</script>
<asp:FileUpload ID="FileUploadEventosCasal" CssClass:"multi" runat="server" />
但這只是運行更改。 當我嘗試上傳時,它不起作用。 這是按鈕事件:
protected void ButtonInsMultipleUpload_Click(object sender, EventArgs e)
{
HttpFileCollection fileCollection = Request.Files;
List<byte[]> imgs = new List<byte[]>();
for (int i = 0; i < fileCollection.Count; i++)
{
HttpPostedFile uploadfile = fileCollection[i];
imgs.Add(new byte[uploadfile.InputStream.Length]);
uploadfile.InputStream.Read(imgs[i], 0, imgs[i].Length);
}
}
在ASP.NET 4.5中,FileUpload控件支持上傳多個文件:
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
我發現了我的錯誤。 在按鈕單擊方法中,我進行了以下更改:
HttpFileCollection fileCollection = Request.Files;
List<byte[]> imgs = new List<byte[]>();
for (int i = 0; i < fileCollection.Count; i++)
{
HttpPostedFile uploadfile = fileCollection[i];
byte[] imageBytes = new byte[uploadfile.InputStream.Length];
uploadfile.InputStream.Read(imageBytes, 0, imageBytes.Length);
if(imageBytes.Length > 0)
imgs.Add(imageBytes);
}
感謝您的幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.