当迭代httpfilecollection时,为什么要获得httppostedfile而不是httppostedfilebase?
我在httpfilecollection上迭代,并尝试获取列表< httppostedfilebase>结果。
public List<HttpPostedFileBase> GetFiles()
{
HttpFileCollection files = HttpContext.Current.Request.Files;
List<HttpPostedFileBase> result = new List<HttpPostedFileBase>();
foreach (string fileName in files)
{
HttpPostedFileBase castedFile = files[fileName]; //This is HttpPostedFile and not HttpPostedFileBase
result.Add(castedFile);
}
return result;
}
我如何获得列表&lt; httppostedfilebase&gt;从httpfilecollection中?
I'm iterating over an HttpFileCollection and trying to get a List<HttpPostedFileBase> as the result.
public List<HttpPostedFileBase> GetFiles()
{
HttpFileCollection files = HttpContext.Current.Request.Files;
List<HttpPostedFileBase> result = new List<HttpPostedFileBase>();
foreach (string fileName in files)
{
HttpPostedFileBase castedFile = files[fileName]; //This is HttpPostedFile and not HttpPostedFileBase
result.Add(castedFile);
}
return result;
}
How can I get a List<HttpPostedFileBase> out of an HttpFileCollection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
httppostedfile 不是源自httppostedfilebase。如果您真的想返回列表&lt; httppostedfilebase&gt; instead of List, then wrap each HttpPostedFile object within an HttpPostedFileWrapper object:
As the httppostedfilewrapper文档说:
HttpPostedFile does not derive from HttpPostedFileBase. If you really want to return List<HttpPostedFileBase> instead of List<HttpPostedFile>, then wrap each HttpPostedFile object within an HttpPostedFileWrapper object:
As the HttpPostedFileWrapper documentation says: