多文件上传
首先HTML 源文件中 添加文件上传Html组件
<script language="javascript" type="text/javascript">
function addFile()
{
//添加文件上传Html组件
var str ='<input type="file" name="File" /></br>'
document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
}
</script>
后台:
HttpFileCollection files = HttpContext.Current.Request.Files;
for (int iFile = 0; iFile < files.Count; iFile++)
{
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("Fll/") + fileName);
}
}
Response.Write("文件上传成功!");
当遇到大文件上传需要修改配置文件:
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="1024000" executionTimeout="900"/>