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);
}