<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("请选择文件"); } }