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
from
accepts an
the constructor:
TheVillageIdiot brings up a great point about the better looping construct, and it will work for you if you're scope exposes the
of the current HTTP context (e.g. on a
but not in
If you have LINQ available, you could use that as well:
A quick peek at Reflector indicates that
HttpPostedFileWrapperinherits
from
HttpPostedFileBaseand
accepts an
HttpPostedFilein
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
Requestproperty
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); }
相关文章推荐
- Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'(无法将类型'ASP.login_aspx' 转换为'System.Web.UI.WebControls.Lo
- 发布网站时CS0030: Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'
- cannot implicitly convert type System.DateTime? to System.DateTime.
- Cannot convert type ‘ASP.login_aspx’ to ‘System.Web.UI.WebControls.Login’的解决方法
- System.Web.HttpException: The file "~/xxx//Index.cshtml" cannot be requested directly because it cal
- Cannot assign value of type 'java.lang.String' to property 'file' of type 'org.apache.struts.upload.FormFile'
- Cannot convert type ‘ASP.login_aspx’ to ‘System.Web.UI.WebControls.Login’的解决方法
- 'CreateFileW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR'
- Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching e
- Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'
- VS2005的BUG:Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'
- VS的bug :Cannot convert type 'ASP.login_aspx' to 'System.Web.UI.WebControls.Login'
- Can't open file 'folder/.svn/tmp/text-base/file.svn-base': The system cannot find the file specified的实用解决方法
- error C2440: 'initializing' : cannot convert from 'boost::filesystem3::path' to 'std::basic_string<_
- cannot convert from 'wchar_t *' to 'ATL::CStringT ‘s solution
- (菜鸟级别)解决用VC创建新线程易出的问题error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (_
- error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [2]' to 'LPCWSTR'
- Cannot convert anonymous method to type 'System.Delegate' because it is not a delegate type
- cannot convert from 'wchar_t *' to 'ATL::CStringT ‘s solution
- cannot convert from 'const char [n]' to 'LPCWSTR'2009