HttpFileCollection files = HttpContext.Current.Request.Files;
foreach (string key in files.AllKeys)
{
HttpPostedFile file = files[key];
if (!string.IsNullOrEmpty(file.FileName))
{
file.SaveAs(HttpContext.Current.Server.MapPath("~/App_Data/") + file.FileName);
}
}
上传大小限制 webconfig:
<configuration>
<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout="200" enable="true" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="104857600" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
第一个文件的单位是 kb
第二个文件的单位是 byte