asp.net - Cannot implicitly convert type 'System.Web.HttpPostedFile' to 'System.Web.HttpPostedFileBase' -


I have a method that does not create, there are errors with this message:

< P> Can not change indirect type ' System.Web.HttpPostedFile ' ' System.Web.HttpPostedFileBase '

I really can not For the need to have this type, instead of HttpPostedFileBase HttpPostedFile , I have tried boxing and it does not work:

  foreach (InputTagName HttpContext.Current.Request files in the string) {HttpPostedFileBase fileb ES = HttpContext.Current.Request.Files [inputTagName]; If (filebase.ContentLength> gt; 0) {if (filebase.ContentType.Contains ("image /")) {SaveNonAutoExtractedThumbnails (doc, filebase); The text after the "itemprop =" text "> 

reflector indicates taking a glimpse of HttpPostedFileWrapper

/ Code> HttpPostedFileBase and accepts in a HttpPostedFile creator:

  foreach (string in httpContext.Current.Request.Files InputTagName) {HttpPostedFileBase filebase = new HttpPostedFileWrapper (HttpContext.Current.Request.Files [inputTagName]); If (filebase.ContentLength & gt; 0) {// ...  

TheVillageIdiot brings much talk about building better looping, and if you are exposed to the scope of this Will work for the request property (such as page but not Global.asax of the current HTTP reference):

< Pre> foreach (HttpPostedFile file in the request. Files) {HttpPostedFileBase filebase = new HttpPostedFileWrapper (file); // ..

If you have LINQ available, you can use it as well:

  files = Request.Files.Cast & Lt; HttpPostedFile & gt; (). Select (file = & gt; new HTTP posted file on (file)). Where (file = & gt; file; contact line & gt; 0 & amp; file; content type. Start ("image /"); Foreign file (file) {SaveNonAutoExtractedThumbnails (Doctor, File); }  

Comments