[英]Using HTML5 multiple file upload with ASP.NET
我正在嘗試使用上傳多個文件
<input id="testUpload" type="file" multiple="true"/>
(是的,我知道它在IE上不起作用)。 但我的問題是,在代碼中我應該怎么做才能遍歷每個文件並上傳它?
我正在努力
foreach(HttpPostedFile file in Request.Files["testUpload"]){
}
但我明白了
foreach statement cannot operate on variables of type 'System.Web.HttpPostedFile' because 'System.Web.HttpPostedFile' does not contain a public definition for 'GetEnumerator'
我知道我可以做multiple = "false"
:
HttpPostedFile file = Request.Files["testUpload"];
然后對該文件進行操作。 但是,如果我選擇多個文件呢? 如何使用foreach
迭代每個?
您試圖迭代一個文件而不是集合。
更改
foreach(HttpPostedFile file in Request.Files["testUpload"]){
}
至
編輯 - 根據評論更改為for循環
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFileBase file = Request.Files[i];
if(file .ContentLength >0){
//saving code here
}
謝謝你,謝謝你,謝謝你。 它救了我的一天。
但是,我不得不使用HttpPostedFile而不是HttpPostedFileBase。
for (int i = 0; i < Request.Files.Count; i++) { **HttpPostedFile** file = Request.Files[i]; if(file .ContentLength >0){ //saving code here } }
無論哪種方式,這都很棒
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.