ASP.Net 文件上传控件的问题!很郁闷!
<form id="form1" enctype="multipart/form-data" action="http://localhost:51043/FileHelper.aspx" method="post" name="form1">
<div>
<input id="fuFileUploader" type="file" name="fuFileUploader">
<input id="btnUpload" type="submit" value="上传" name="btnUpload">
</div>
</form>
为什么这种不行?
而非要 asp.net 页面生成的那种页面才能生成?
<form name="form1" method="post" action="FileHelper.aspx" id="form1" enctype="multipart/form-data">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTI3MTMxMTcxNw9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YWRkX5pJZL+bOalZcMHVZy1OCrq+JIr5qIIfQLE+Jch07/M=" />
</div>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLWzq2ACwLt3oXMA0hkwLfBdD0ZLPnnlBA/7EKsXZi9bQp9ZKKSc3/JiHIz" />
</div>
<div>
<input type="file" name="fuFileUploader" id="fuFileUploader" />
<input type="submit" name="btnUpload" value="上传" id="btnUpload" />
</div>
</form>
------解决方案--------------------
<form id="form1" enctype="multipart/form-data" action="http://localhost:51043/FileHelper.aspx" method="post" name="form1">
<div>
<input id="fuFileUploader" type="file" name="fuFileUploader">
<input id="btnUpload" type="submit" value="上传" name="btnUpload">
</div>
</form>
应该也是可以的。
FileHelper.aspx里面写
protected void Page_Load(object sender, EventArgs e)
{
HttpPostedFile p = Request.Files["fuFileUploader"];
p.SaveAs(Server.MapPath("~/" + System.IO.Path.GetFileName(p.FileName)));
}
------解决方案--------------------参考这个