fileupload 上传控件

<div>
<asp:FileUpload ID="FileUpload1" runat="server" />

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="上传" />
</div>

    

protected void Button1_Click(object sender, EventArgs e) { if (this.FileUpload1.HasFile) { string fileName = Path.GetExtension(this.FileUpload1.FileName); string path = Server.MapPath("upload/"); //在上传的同时重命名 this.FileUpload1.SaveAs(path+Guid.NewGuid()+fileName); Response.Write("上传成功!"); } else { Response.Write("请选择文件"); } }

 

posted @ 2017-11-20 08:48  enych  阅读(139)  评论(0编辑  收藏  举报