加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 使用ASP.NET上的HTML5多文件上传

发布时间:2020-12-16 00:22:10 所属栏目:百科 来源:网络整理
导读:我正在尝试使用上传多个文件 input id =“testUpload”type =“file”multiple =“true”/ (是的,我知道它在IE上不起作用).但我的问题是,在代码中我应该怎么做才能遍历每个文件并上传它? 我尝试着 foreach(HttpPostedFile file in Request.Files["testUploa
我正在尝试使用上传多个文件

< 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'

我知道我可以做多个=“假”:

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

  }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读