[英]How to display the image preview when its uploaded
What I want is, when I upload the image from the FileUpload tag as soon as it displays the name of the image, in the image box below it, shows the preview of the image which is being uploaded. 我想要的是,当我从FileUpload标记上传图像时,只要它显示了图像的名称,就会在其下方的图像框中显示正在上传的图像的预览。
The tag for file upload 文件上传标签
<asp:FileUpload ID="FileUpload1" CssClass="form-control" runat="server" width="280px" />
Tag for the image 图片标签
<asp:Image ID="Image1" runat="server" Height="221px" Width="212px" />
The code behind is 后面的代码是
string path = Server.MapPath("~/Images/");
if(FileUpload1.HasFile)
{
string extension = Path.GetExtension(FileUpload1.FileName);
FileUpload1.SaveAs(path + FileUpload1.FileName);
string name = "~/Images/" + FileUpload1.FileName;
Image1.ImageUrl = name;
}
The "Images" folder is on the host machine. “图像”文件夹位于主机上。 The image is uploaded by the user. 图像由用户上传。 And on the same page(form) the preview of the image should be displayed. 并且应在同一页(窗体)上显示图像预览。
just use this code it is working in my project. 只需使用此代码即可在我的项目中使用。
` `
if (uploadfilee.HasFile)
{
string str = uploadfilee.FileName;
uploadfilee.PostedFile.SaveAs(Server.MapPath(".") + "/images/" + str);
string path = str.ToString();
image1.Imageurl = path;
}
` `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.