Image control in asp.net? - asp.net

In web application, i am trying to display image in .aspx page, for that i write code like this in page_load event ,
Image1.ImageUrl = #"C:\Users\Public\Pictures\Sample Pictures\Koala.JPEG";
but image is not displaying, can you help me thank you.

there is problem with the path of image ...you need to give relative path for image rather than physical path
something like this
Image1.ImageUrl="~/Images/Bird1.jpg"
here image is in the Images folder of the application. i.e.which is part of project
First create a Images folder in your Solution Explorer. Then store your image in that folder and refer like as below.
Example
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Bird1.jpg" />
Check in deatil : Image Control Example

You cannot use your local path as the path to your image, instead place the web site url with a relative path to the image

Related

How to display image on web page from ADODB.stream object

I have a classic ASP question.
I need to show images on my webpage.
But because of the security reasons, I cannot simply put all of my images in the images folder in my website folder and I need to put them outside of my website folder.
For example, my website folder is located at:
C:\Inetpub\wwwroot\mysite\
But I need to put images (which I want to show on my web pages) at:
C:\images\
I am trying to use ADODB.stream object to pull the images using ASP vb codes as shown below:
<%
Response.ContentType = "image/png"
Set adoStream = Server.CreateObject("ADODB.Stream")
adoStream.Open
adoStream.Type = 1
FPath = "C:\images\1.png"
adoStream.LoadFromFile FPath
Response.BinaryWrite adoStream.Read
adoStream.Close
Set adoStream = Nothing
Response.End
%>
When I launch this webpage in internet explorer, the page shows a File Download window/message for downloading the image file "1.png" rather than displaying the image on the web page.
How can I fix the code to show the image on the web page rather than downloading the image file?
That code generates an image as the return type, so there is no HTML to display the image in, if you call this code directly say it's called image.asp then you would do something like this in another page that displays HTML.
<img src="image.asp" />
This will call your code and output the raw image binary as this is what <img> expects.
If you want to produce multiple images from the file system or database pass a querystring parameter such as ?id=yourimage and change the code to select different images.

How to take image source from code behind after updating it from client side

I have the following scenario.
User is trying to update the profile image , I am using uploadify plugin to upload image to server , and in callback I am setting
<img src="" runat="server" class="user-image" id="uploadedImage" />
SRC attribute to the uploaded path. This part is working good , then when user clicks on Save button , i need somehow to get new picture path and save it to database.
user.ImageUrl = this.uploadedImage.Attributes["src"];
doen't brings a new picture path , and returns a previous path.
Can someone help pls ?
If you want to accomplish this you may use using hidden field, among other ways.
Please refer to: http://www.codeproject.com/Articles/603102/Persist-JavaScript-changes-on-postback,http://forums.asp.net/t/1428896.aspx/1,http://forums.asp.net/t/1285473.aspx.

CuteWebUI.Uploader (Ajax Uploader)

Q.1. When a image file is uploaded via AjaxUplaoder of CuteWebUI.Uploader it saves file like this
persisted.057fe17e-9707-4f3a-91b7-250239b19c2f.10.JPG.resx
in which "10.jpg" is Image file name and Other "persisted.057fe17e-9707-4f3a-91b7-250239b19c2f.10.JPG.resx" I dont know what is this?
Kindly help me to extract file name from this given format "persisted.057fe17e-9707-4f3a-91b7-250239b19c2f.10.JPG.resx" so that I can show image on Image Control of ASP.Net that is uploaded image file via this Ajax Uploader. This ajax uploader's property 'args.filename' gives file name on 'FileUploaded' event.
look here for the solution of your problem: http://ajaxuploader.com/document/scr/html/How-to-save-uploaded-file.htm

What could cause this image to not display?

I have an ASP.NET web app. What I am attempting should be simple: after an image is displayed, I have a Rotate button which should allow the user to rotate the image 90 degrees. Here is the button click code...
Dim i As Image
i = Image.FromFile("C:\Inetpub\wwwroot\myWebApp\MyImage.jpg")
'rotate the picture by 90 degrees
i.RotateFlip(RotateFlipType.Rotate90FlipNone)
're-save the picture as a Jpeg
i.Save("C:\Inetpub\wwwroot\myWebApp\MyImage.jpg",System.Drawing.Imaging.ImageFormat.Jpeg)
'tidy up after we've finished
i.Dispose()
The image and button used here are non-remarkable. When I created a sample app with just 1 page this works perfectly. However, when I put in into my main app, even if its in a new page, all by itself with nothing else, not even a masterpage, it does, in fact rotate the image and write it back to the file system, but it doesn't show the rotated file. It shows the image as it was. UNTIL I hit F5, then, no matter how many times I hit the button, it works perfectly. I have tried eveything i can think of to clear the cashe to no avail.
Are you re-requesting the image using an update panel or some other mechanism? You will be able to force a refresh by putting something like a timestamp or similar GET parameter on the IMG src, or in the ASP:Image source.
Instead of saving the image back to the web root you can keep the original image as is and just stream the rotated image to the client.
<img src="RotateImage.aspx?Image=MyImage.jpg&Rotate=90" />
and then in your RoateImage.aspx do the same load/rotate work and:
i.Save(Response.OutputStream, ImageFormat.Jpeg)
Response.ContentType = "image/jpeg"
The image is served from the cache, that is why it is not shown updated. To show the newer version of the same image. You may attach a query string to the path of the image. For example,
<img src='/images/image.jpg?<%= DateTime.Now.Ticks %>' />

Image URL is correct but image not showing

I have a website on GoDaddy. All permissions are set correctly and the image DOES exist. However when the page loads the image for the item selected does not show. Here is my code
imagepath = "~/spaimages/" + currentSpaModel.Name.ToString() + ".png";
if (File.Exists(Server.MapPath(imagepath)))
{ this.spaimage.ImageUrl = Server.MapPath(imagepath); }
spaimage is an ASP control and thr URL that the image is set to is D:\hosting\xxxxxxx\calspas\spaimages\modelname.png
What am I doing wrong.
The file path D:\hosting\xxxxxxx\calspas\spaimages\modelname.png is the folder where the image resides on the web server. You are sending this as the <img> tag's src attribute, which tells the browser, "Go get the image at D:\hosting\xxxxxxx\calspas\spaimages\modelname.png." The browser cannot go off to the D drive of the web server, so it looks on its own D drive for that folder and image.
What you mean to do is to have the <img> tag's src attribute be a path to a folder on the website. You're just about there - just drop the Server.MapPath part when assigning the image path to the ImageUrl property. That is, instead of:
this.spaimage.ImageUrl = Server.MapPath(imagepath);
Do:
this.spaimage.ImageUrl = imagepath;
See if that works.
Thanks
Often, if an image "does not show" (I assume a red-x-equivalent is being displayed to show "broken image"), I right-click the broken image, copy the URL and open the URL in a separate browser window.
This way, when the image is being generated by some script, I see any error text that the script might have shown. If not, the real image would be displayed.
In addition, add an else block to the
if (File.Exists(Server.MapPath(imagepath)))
like
else
{
Response.Write(string.Format(
"File does not exist at '{0}'.",
Server.MapPath(imagepath)));
}
For debugging purposes.

Resources