您的位置:首页 > 理论基础 > 计算机网络

Cannot implicitly convert type 'System.Web.HttpPostedFile' to 'System.Web.HttpPostedFileBase'

2014-07-14 18:11 579 查看
http://stackoverflow.com/questions/3071902/cannot-implicitly-convert-type-system-web-httppostedfile-to-system-web-httppo

A quick peek at Reflector indicates that
HttpPostedFileWrapper
inherits
from
HttpPostedFileBase
and
accepts an
HttpPostedFile
in
the constructor:
foreach (string inputTagName in HttpContext.Current.Request.Files)
{
HttpPostedFileBase filebase =
new HttpPostedFileWrapper(HttpContext.Current.Request.Files[inputTagName]);

if (filebase.ContentLength > 0)
{
//...


TheVillageIdiot brings up a great point about the better looping construct, and it will work for you if you're scope exposes the
Request
property
of the current HTTP context (e.g. on a
Page
,
but not in
Global.asax
):
foreach (HttpPostedFile file in Request.Files)
{
HttpPostedFileBase filebase = new HttpPostedFileWrapper(file);
// ..


If you have LINQ available, you could use that as well:
var files = Request.Files.Cast<HttpPostedFile>()
.Select(file => new HttpPostedFileWrapper(file))
.Where(file => file.ContentLength > 0
&& file.ContentType.StartsWith("image/"));

foreach (var file in files)
{
SaveNonAutoExtractedThumbnails(doc, file);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐