Ahmed Khalil
Ahmed Khalil

Reputation: 85

Display Image in label in ASP.Net c#

I have an empty label when i try to display image from my computer to this label this is the code :

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

Upvotes: 1

Views: 11283

Answers (3)

Dnyanesh
Dnyanesh

Reputation: 2343

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.

Upvotes: 2

Mariusz
Mariusz

Reputation: 481

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.

Upvotes: 0

Raghubar
Raghubar

Reputation: 2788

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' />";

Upvotes: 0

Related Questions