显示图像

时间:2011-02-14 10:40:30

标签: .net asp.net

如何使用fileupload浏览图像位置并将其显示到图像控件

1 个答案:

答案 0 :(得分:0)

试试这个:

在你的asp.net页面中:

<form id="form1" runat="server">
<div>
    <asp:Image ID="uploadedImage" runat="server" />
    <asp:FileUpload ID="fileUploadControl" runat="server" />
    <asp:Button ID="btnSubmit" runat="server" Text="submit" />
</div>
</form>

在其背后的代码中:

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        if (fileUploadControl.HasFile)
        {
            string location = "Images/imageName.png";
            fileUploadControl.SaveAs(Server.MapPath("~/" + location));
            uploadedImage.ImageUrl = location;
        }
    }
}

代码并不完美。但它给了你一个暗示......