简体   繁体   English

上传图片后如何显示图片预览

[英]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.

相关问题 显示所有上传文件的预览 - Display Preview of All Uploaded Files 如何在实际发送到服务器之前显示正在上载的图像的预览 - How to show preview of image being uploaded before actually sending it to server 如何在ASP .NET应用程序中显示上载的图像? - How to display uploaded image in asp .net application? 当模型为null时如何显示模型中的字节数组图像? - How to display a byte array image from model when its null? 在asp.net的图像控件中将图像保存到数据库之前,如何预览 - how to preview uploaded image before saving it in database in image control in asp.net 在使用asp.net或jquery保存之前,如何在文件上传控件中预览上传的图像? - How to preview uploaded image in file upload control before save using asp.net or jquery? 为什么在粘贴到 Excel 时图像显示的大小大于其实际大小,我如何才能使其以自然大小显示? - Why does an image display at greater that its actual size when pasting into Excel, and how can I get it to display at its natural size? 如何查看上传图片的预览(不要!)然后保存它的地址? - how can I see a preview of uploaded image (don!) and then save it's address? 如何从 razor 页面中的文件夹中显示上传的图像 - how can i display uploaded image from a folder in razor pages 如何在angularJS和MVC中使用路径显示上传的图像? - How to display uploaded image using path in angularJS and MVC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM