Request.Files将同一文件上传为ASP.NET MVC

编程入门 行业动态 更新时间:2024-10-20 05:23:32
本文介绍了Request.Files将同一文件上传为ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName]; //Save file content goes here fName = file.FileName; if (file != null && file.ContentLength > 0) { subPath = ConfigurationManager.AppSettings["SubPath"].ToString() + "/" + currentUserId; bool isExists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!isExists) System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); string path = System.IO.Path.Combine(Server.MapPath(subPath), System.IO.Path.GetFileName(file.FileName)); file.SaveAs(path); } }

如果我上传了多个文件,我会得到n次相同的文件.

If i upload multiple files i get the same file n number of the times.

我正在使用此控件: github/kartik-v/bootstrap-文件输入

我的cs.html

codepen.io/anon/pen/aekqm

请在我的完整代码上方找到.

Please find above my complete code.

推荐答案

解决了我的问题:

使用下面的代码

for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase file = Request.Files[i]; }

代替两次获取相同文件的foreach循环

instead of the foreach loop which was taking the same file twice

更多推荐

Request.Files将同一文件上传为ASP.NET MVC

本文发布于:2023-11-24 23:00:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627237.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件上传   Files   Request   MVC   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!