简体   繁体   中英

Display Image in label in ASP.Net c#

当我尝试将图像从我的计算机显示到此标签时,我有一个空标签这是代码:

Label1.Text += " " + "<img src='C:/Users/AA/Documents/Bureau/car/img/image3.jpg'>";

Include image in your project for example if you include in images folder. Following code will for you.

Label1.Text += "<img src='images/image3.jpg'></img>";

If you want to open it from same path try this

Label1.Text += " " + "<img src='file://C:/Users/AA/Documents/Bureau/car/img/image3.jpg'>";

Note: file://C:/Users/AA/Documents/Bureau/car/img/image3.jpg will be loaded in IE but not in Chrome or Firefox because loading files form direct path is considered security thread in Chrome and Firefox.

Considering all this i will suggest you to put images in Image and access them from there is simplest way to do it.

Sorry, I missed that it's ASP.net

You'll probably want to use Server.MapPath("~/image.jpg") stuff to be relative to deployment location. And close the tag.

This is working example in asp .net c#.

<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

Label1.Text = "<img alt='' src='images/download-img.jpg' />";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM