enctype="multipart/form-data"
如果設置
enctype="multipart/form-data"
那么就可以使用HTML的 <input type=file>控件
但必須設置id和name屬性 這樣服務端才能獲取到
如果沒有設置enctype="multipart/form-data"
就要用服務器控件來 也就是要有runat=“server”
<form id="form1" runat="server" method="post" enctype="multipart/form-data">
<div>
<input type="file" />
<asp:Button ID="btnUpload" runat="server" Text="开始上传" οnclick="btnUpload_Click" />
</div>
</form>
protected void btnUpload_Click(object sender, EventArgs e)
{
//int intCount = RequestClass.GetFormInt("hdcount", -1);
HttpFileCollection Files = HttpContext.Current.Request.Files;
for (int i = 0; i < Files.Count; i++)
{
HttpPostedFile PostedFile = Files[i];
if (PostedFile.ContentLength > 0)
{
string FileName = PostedFile.FileName;
string strExPrentFile = FileName.Substring(FileName.LastIndexOf(".") + 1);
string sFilePath = "/uploadfile/hotel/" + StringClass.makeFileName24() + i + strExPrentFile;
PostedFile.SaveAs(Server.MapPath(sFilePath));
}
else
{
//this.LabMessage.Text = "不能上传空文件";
}
}
}