界面代码
<asp:Image ID="Image1" runat="server" ImageUrl="~/pic/def.gif" Width="85px" /> <br /> <asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <asp:Button ID="Button5" runat="server" onclick="Button5_Click" Text="Button" />
cs文件代码
protected void Button5_Click(object sender, EventArgs e) { if (FileUpload1.FileName != "") { string file = FileUpload1.FileName; //得到文件名 FileUpload1.PostedFile.SaveAs(Server.MapPath("pic/" + file)); //上传图片 Image1.ImageUrl = "~/pic/" + file; } }