Below is my html image control:
<img alt="" src="C:\Users\hkalidindi\Desktop\Feedback.jpg" style="height: 19px; width: 20px"/>
But after debugging it is not showing me any image:
I am new to dotnet..please help me to solve this issue...I know how to display image in image control but i am bit confused about the html image control...
Use image only from the content of your website. So copy the image in your website folder say Images and access your image as <img alt="" src="..\images\Feedback.jpg" style="height: 19px; width: 20px"/>. Or you could use Asp.NET Image control and set image path in Server code using
myImage.ImageUrl=Server.MapPath("Images\Feedback.jpg");
"C:\Users\hkalidindi\Desktop\"
Is only local, try uploading it to a website such as http://imageshack.us, http://tinypic.com, grab the direct link and put that in the source.
<img src="URL">
Here URL = The url of the image.
Possible values (for src):
An absolute URL - points to another web site (like src="http://www.example.com/image.gif")
A relative URL - points to a file within a web site (like src="image.gif")
Refer: HTML src Attribute
You are trying to call the image in your local folder. Add the image to the 'Images' folder in your solution and link to that.
Make sure the image is being referenced from a folder that is in your websites application/dir. Then you can reference it simply by using a tag like so:
<asp:Image id="imgFeedback" runat="server" ImageUrl="~/_common/img/feedback.jpg" />
Or set the image path on the server side:
this.imgFeedback.ImageUrl = Server.MapPath("\_common\img\feedback.jpg\");
Related
I want to create a website which will store 2 images in the "home" page, which will lead to 2 different pages. In the case, I'm using the Image object from the toolbox. When I'm trying to assign the ImageUrl, it don't appear to find anything at all, regardless of the format. I've tried with multiple photos, different folders, there's the result:
I've also tried to change it programatically in C#, not working, as well:
Image1.ImageUrl = #"Images/left.jpg";
Should I use the usual <img src=""/> for finding images? Thank you very much!
Right click on that image shown and choose "include in project" and then try to give imageUrl
If you are sure that your path value contains the appropriate path from the ImageFiles directory, then you should be able to use the following :
<asp:Image ID="Image1" runat="server" ImageUrl='~/ImageFiles/<%# Eval("path")%>' />
or use the integrated string formatting of the Eval method as shown here :
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("path", "~/ImageFiles/{0}") %>' />
From the code behind you could do something like below including application base URL some thing like below-
Image1.ImageUrl = #"~/Images/left.jpg"
Please refer the below discussion for more information -
Image isn't showing in Image and ImageButton
ASP.NET will automatically replace the ~ with your application's base
URL, because Image1 is a server control
im doing a project using .net MVC web Application.
i recently used a code to create a new thumbnail to photos (re defining the sizes of a photo) . and now i'm trying to print the photos using the 'img' tag of HTML but without success.
the thumbnail creating code :
Image thumbnail = Image.FromFile(destPath);
thumbnail = (Image)(new Bitmap(thumbnail, new Size(this.m_thumbnailSize, this.m_thumbnailSize)));
thumbnail.Save(destPathThumb);
now for the img printing :
#Html.DisplayFor(modelitem=>item)
<img class="img-rounded" style="border-radius:50%" src=#item alt="">
item is the path to the picture and it is currect (ive checked serveral times).
any ideas what i could be ?
thank you for helping me ! :)
EDIT: the img tag prints normal pictures -> pictures that my program did not create(as i said,my program created thumbnail pictures)
I wonder if it is not releasing the file lock on the image, I have had that problem in the past. You have to be very careful about releasing those Image and Bitmap objects.
Something like this might work, as it will dispose the image before the page starts using it:
using(Image thumbnailoriginal = Image.FromFile(destPath)){
using(Image thumbnail = (Image)(new Bitmap(thumbnailoriginal, new Size(this.m_thumbnailSize, this.m_thumbnailSize)))){
thumbnail.Save(destPathThumb);
}
}
It seems like a lot of brackets on the end but thats ok.
If it still does not work, can you post the html that is sent to the browser, you can do that using "View page source" from the right-click menu in Chrome.
Now we have the html that is going to the browser, we can see that the src attribute is pulling directly from the C drive, rather than from a web url:
<img class="img-rounded" style="border-radius:50%" alt="" src="C:\Users\Operu\Desktop\dest\Thumbnails\2018\6\Sasuke.png">
Normally we would want to see something more like this:
<img class="img-rounded" style="border-radius:50%" alt="" src="\Thumbnails\Sasuke.png">
Could you post the model and controller files next please, so we can see what type of object the #item is when it hits your view. Then we can hopefully get it to pull the relative url address instead of the file location.
I have an img tag.
(I am using just image and not asp.net because it is an imageMap that I have working with an img).
I dynamically set the src as below in 3 different ways. The first way works and the image is included in the project. But when I try to add the src the 2nd way it fails to display the image. That image is not part of the project. I have even tried the 3rd way for a different location but it fails to load as well. It is not part of the project either. What I need to be able to do is load ans image src dynamically that is not included in the project and have it display.
<img runat="server" class="ImageMap" id="ImageMapID" src="" usemap="#imagemap" />
ImageMapID.Attributes["src"] = #"/Icons/XXXX XXXX.png";//first way that works
ImageMapID.Attributes["src"] = #"/documents/XXXXX/XXXX_04092017.pdf"; // second way that fails
ImageMapID.Attributes["src"] = #"file://C:/temp/XXXXXXXX.pdf";// third way that fails
Any ideas anybody? I should add they are different images but they should all work.
First thing you should know, PDF files are not image objects, so you can't use img tag to embed it. You need to use iframe tag instead:
<iframe src="file:///C:/temp/XXXXXXXX.pdf" style="width: 100%; height: 100%;" frameborder="0" scrolling="no">
...
</iframe>
Or use embed/object tag with same file path:
<embed src="file:///C:/temp/XXXXXXXX.pdf" width="600" height="400" type="application/pdf">
<object type="application/pdf" data="file:///C:/temp/XXXXXXXX.pdf" title="XXXXX" width="600" height="400" >...</object>
If you want to include local file path for images, use file reference path or relative path with proper directory structure shown in example below:
ImageMapID.Attributes["src"] = #"file:///C:/temp/Icons/XXXXXXXX.png";
// watch out for current relative path you're using
ImageMapID.Attributes["src"] = #"../../temp/Icons/XXXXXXXX.png";
Note that Windows local drive path uses this format to refer any files for use in any HTML elements with source attribute:
file:///[drive letter]:/[path_to_resource]/[filename].[extension]
References:
How to properly reference local resources in HTML?
Recommended way to embed PDF in HTML?
so started using a new method for dynamicly displaying images inserted into my database. This is the asp.net code
<asp:ImageButton ID="ImageButton1" ImageUrl='<%#Eval ("ImageUrl", "~/img/{0}") %>' Width="200px" PostBackUrl='<%#Eval ("ProductID", "Product.aspx?ProductID={0}") %>' runat="server" />
now, as you can see what it does is getting the "ImageUrl" from my database depending on what the ProductID is, and then shows that as the image url. Example in my folder /img/ i have a picture called "pic.jpg" then this code would make the image url "~/img/Pic.jpg" now how would i add a new image into the table from the backend? i would have to make a flileupload control upload the file to the "img" folder and then insert only the file name as the "ImageUrl" in the database table. How is this done? do you have any examples or can point me in the right direction?
thanks!
all answers appreciated!
ImageButton is actually a html input type image. So you should not use it for just display purposes. You can use Image control or even use html img tag.
Check this link for FileUpload control
http://asp.net-tutorials.com/controls/file-upload-control/
Check this link for Image control
http://www.w3schools.com/aspnet/showaspx.asp?filename=demo_image
How to add System.Drawing.Image object to Asp:Image Control but I dint have imageId in my table.Image field is in another table..i retrieve image from database in Image object.i want to display it in asp:Image control or grid view.how to do it?? pls send reply... C#
The Image class and <asp:image> control are completely different thing.
You need to have a page or http handler to write the Image object as an image file such as .jpg / .png / .gif. And then use the <asp:image> control to access the URL of your page or http handler to get the image file you generated and display it. <asp:image> basically only render a HTML <img> tag with the URL of the image.
You can use this ASP.NET module and the SqlReader plugin to serve images directly from the database.
You can then reference the images like so:
<asp:Image runat="server" ImageUrl="/sqlimages/[imageidhere]" />