Raf*_*del 3 c# asp.net file-io html5 file-upload
我正在尝试使用上传多个文件
<input id="testUpload" type="file" multiple="true"/>
(是的,我知道它在IE上不起作用).但我的问题是,在代码中我应该怎么做才能遍历每个文件并上传它?
我尝试着
foreach(HttpPostedFile file in Request.Files["testUpload"]){
}
Run Code Online (Sandbox Code Playgroud)
但我明白了
foreach statement cannot operate on variables of type 'System.Web.HttpPostedFile' because 'System.Web.HttpPostedFile' does not contain a public definition for 'GetEnumerator'
Run Code Online (Sandbox Code Playgroud)
我知道我可以这样做multiple = "false":
HttpPostedFile file = Request.Files["testUpload"];
Run Code Online (Sandbox Code Playgroud)
然后对该文件进行操作.但是,如果我选择多个文件呢?如何迭代每个使用foreach?
hea*_*150 13
您试图迭代一个文件而不是集合.
更改
foreach(HttpPostedFile file in Request.Files["testUpload"]){
}
Run Code Online (Sandbox Code Playgroud)
至
编辑 - 根据评论更改为for循环
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFileBase file = Request.Files[i];
if(file .ContentLength >0){
//saving code here
}
Run Code Online (Sandbox Code Playgroud)