如何使用fileupload浏览图像位置并将其显示到图像控件
答案 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;
}
}
}
代码并不完美。但它给了你一个暗示......