首页 新闻 赞助 找找看

如何用Lamda遍历HttpFileCollection的所有HttpPostedFile

0
悬赏园豆:30 [已解决问题] 解决于 2016-06-14 22:48

如何用Lamda(比如Select)遍历HttpFileCollection中的所有HttpPostedFile值

C#
dudu的主页 dudu | 高人七级 | 园豆:31075
提问于:2016-06-14 17:37
< >
分享
最佳答案
0
var files = System.Web.HttpContext.Current.Request.Files;
files.AllKeys.Select(k => files[k]);
dudu | 高人七级 |园豆:31075 | 2016-06-14 22:48
其他回答(1)
0

写一个扩展方法,比如:

public static class Extensions
    {
        public static List<HttpPostedFile> ToHttpPostedFileList(this HttpFileCollection collection)
        {
            if (collection == null)
                throw new ArgumentNullException("collection");
            var httpPostedFileList = new List<HttpPostedFile>();
            for (int i = 0; i < collection.Count; i++)
            {
                httpPostedFileList.Add(collection[i]);
            }
            return httpPostedFileList;
        }
    }

 

收获园豆:30
jello chen | 园豆:7306 (大侠五级) | 2016-06-14 18:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册