Getting images from db and displaying in WebControls.Image

So I have the following code which is getting my image, but unfortantly all that is displayed is a 'x' where the Image controls is placed.

 In the main aspx.cs page:

1                                                //get the image in bytes from the database
2                                                byte[] imageInBytes = image.LoadImage(Convert.ToInt32(dr.ItemArray[3]));
4                                                //place in memory stream
5                                                System.IO.MemoryStream memoryStream = new MemoryStream(imageInBytes, 0, imageInBytes.Length, true);
7                                                //place the stream in an image
8                                                System.Drawing.Image imagePhysical = System.Drawing.Image.FromStream(memoryStream);
10                                               imagePreview.Visible = true;
11                                               imagePreview.Width = 300;
12                                               imagePreview.Height = 150;
14                                               imagePreview.ImageUrl = ("ImageHolder.aspx?Image=" + Convert.ToInt32(dr.ItemArray[3]));

than in the second page, which has the Image: 'ImageHolder.aspx' - i pass the image ID to get it from the database


1                if (Request.Params["Image"] != null)
2                {
3                    int requestedParam = Convert.ToInt32(Request.Params["Image"]);
4                    AthenaCMS.Image image;
6                    if ((AthenaCMS.Image)Session[AppConst._Session_Image] != null) { image = (AthenaCMS.Image)Session[AppConst._Session_Image]; }
7                    else { image = new AthenaCMS.Image(); }
9                    //get the image in bytes from the database
10                   byte[] imageInBytes = image.LoadImage(requestedParam);
12                   //place in memory stream
13                   System.IO.MemoryStream memoryStream = new MemoryStream(imageInBytes, 0, imageInBytes.Length, true);
15                   //place the stream in an image
16                   System.Drawing.Image imagePhysical = System.Drawing.Image.FromStream(memoryStream);
17                   imagePhysical.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
19                   Response.ContentType = "image/jpeg";
20                   Response.OutputStream.Write(imageInBytes, 0, imageInBytes.Length);
21               }


I believe the code is correct....but the first page is not moving to the second page and thus not populating my image control.

Any ideas? Thanks!

2/1/2008 8:37:53 AM 93655 articles. 6 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 25


I belive that in the ImageHolder.aspx your first part of code retrieves the image based on the specified 'image' parameter.


byte[] imageInBytes = image.LoadImage(requestedParam);

if(imageInBytes != null && imageInBytes.Length > 0)
	Response.ContentType = "image/jpeg";
	Response.OutputStream.Write(imageInBytes, 0, imageInBytes.Length);
else // read from disk & output here a default image 


 Please make sure that you read properly the image from your storage location. I hope this will help.



Please remember to mark the replies as answers if they help and unmark them if they provide no help.
2/1/2008 11:58:27 AM

thanks, it did :)

also i had an incorrect path to the image i was if any one has the same problem, check the url you are given....try and hard code it and see if it works, than check the url that is being generated! Smile 

2/1/2008 12:49:43 PM

Similar Artilces:

Help to retrieve image from database and display in Web.UI.WebControls.Image
Hi! I am a newbie. I want to retrieve image from database and display it in Web.UI.WebControls.Image.The control name is imgPicFace.And I want when it retrieve from database the control point like this >>>  imgPicFace.ImageUrl = "~/MyKad.bmp"; Please help and provide example code for me. Thank you.SAVE CODE:- 1 Bitmap b = new Bitmap(Server.MapPath("MyKad.bmp")); 2 System.Drawing.Image i = (System.Drawing.Image)b; 3 4 MemoryStream streamP = new MemoryStream(); 5 ...

display image in a image image button
hi   i have to display an image in image button while uploading mycode Image1.ImageUrl = Upload.PostedFile.FileName; is not working thanks Hi You need to save the PostedFile to the disk on the server and then assign it to ImageUrl. Take a look at the following links for more infoprmation on how to do this. Nassabehwww.professionalcsharp.comDon't forget to click "Mark as Answer" on the post that helped you. That way ...

Reading in an image from the web and getting image type
Hi,   I am trying to stream in images from the web and then convert them to byte[] and then plug them into a database "image" field.  I basically have it working but in the end the image is messed up for some reason.  Here is my code:  byte[] returnVal = null;  Stream ImageStream = new WebClient().OpenRead(pageUrl);  int count = 0;while (ImageStream.ReadByte() != -1) count++;   ImageStream.Close();  Stream ImageStream2 = new WebClient().OpenRead(pageUrl); //where pageUrl is the url to the image file  byte[] temp = new byt...

how to display image from web service in an image control
 Hi, I am using web service to fetch image from the video server, and displayed  in the web application, that is working fine,but I am using               Response.ContentType = "image/gif";              Response.BinaryWrite(arrpicture); but I want to display this image in the image control of the web application.Can any one help me out in this.Thanks,     You can do this using an HTTP Handler, using the same technique outlined...

Displaying images in a DW (Getting image dimensions)
PB9.0 Hi all. Can some one help me with the following please: - I want to display an image in a dw. The user types the path and name of the file to be displayed in a text box. I then need to display this in the image object in the DW (this I can do), the problem is the image is being distorted based on the sixe of the image object. How do I get the dimensions of the actual image (could be a bmp, gif or jpg file) so I can set the image object size just prior to loading ? Thanks You could purchase a 3rd party DLL that has functionality to read the file's dimensions. A chea...

Display Image from db Image ID Field
I have an image name stored in a database that I want to display the image for in a datagrid. I need to concatenate the image path and the file extension. Here's what I tried, but is not working- <ItemTemplate> <img src="e:\inetpub\wwwroot\hcso_dvt\records\images\<%#DataBinder.Eval(Container, "DataItem.ImageID" ) %>.jpg"> </ItemTemplate> Help will be greatly appreciated! Thank You!! Lynnette I found another post from someone who said to use the "dataformatstring" property in a bound control to display the image. I t...

Displaying default image when DB Image is empty?
I'm retriving images from a database using the code at the link below as model., if the database dosen't contain a image, how do I specify a default image in the code? /Johan Ch Before you write it you can do a If NOT IsDbNull(myDataReader.Item("PersonImageType")) Then     'write the image End If ***********************Dinakar NethiLife is short. Enjoy it.*********************** (NOTE: I got a XML error when I was trying to post the last reply, so this may be a double post. If so, you can remove one of them.)We...

Display image from image
Let me explain more. I have a Gridview, that displays an image.  Then i have a detailsview displaying an image from the selected value in the gridview.  Simple.  When i click on one of the images from the gridview, it displays the correct image in the detailsview.  Basically, i have two images in each row of the table in the database.The only way this works is if i have "autogenerateselectbutton=true" set.  I do not want the select link next to my image.  I want to be able to pick on the image in the GridView, and have it show the correct image in...

Displaying an image form DB
I have my image stored in SQL database as SqlDbType.image(16) and I would like to display it with help of asp:image control on a web page. Is there a way to do it? (I prefer example) ThanksVlado Take a look @ Sample code..Sushila Bowalekar PatelVisual ASP/ASP.NET MVP I suggest u to not store the image in database. Just store the path of the image in database. Then u can easily retrieve the path & can set the source of asp:Image. AmitThanks & Regards,Amit Batra Thanks Sushila , it works.Vlado...

Image display on web form
I am using ASP.NET 2.0 with C#. I am using an Oracle database as my datawarehouse.I have my images stored as a CLOB data type. I want to pull images to display per user.  Each user has an image so when they login in it should display there image.Here is my code. 1). A stored procedure that will get the actual Base64 value that stores the imagepublic static byte[] _ReadLogo()    {        byte[] buffer;        Object obj = new Object();            &n...

'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'
In my aspx page, I have the following snippet: <%@ Page Language="C#" %><%@ Import Namespace="System.IO" %><%@ Import Namespace="System.Drawing" %>     public System.Drawing.Image Test()    {      ...    }  I keep getting the 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image' error in my Test function (which returns an Image). How do I fix this? Right which is possible; use the full...

CS0104: 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'
 CS0104: 'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'   <%@ Page Language="C#" %> <%@ Import Namespace="System.Drawing" %> <%@Import Namespace="System.Drawing.Imaging" %>   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""><script type="text/C#" runat="server"> void Page_Load() {//The @ means "Ignore escape characters!" in the following string. It is a verbatim //literal string - any backslashes (and newlines) in...

Displaying image from database(image datatype) to image control
Hie all...I'm a newbie at I m currently using 2.0.I m having a problem with displaying images on my web form. Have tried looking thru all codes but i can't find a step by step tutorial for doing so. I understand that in 1.1, the detailsview can automatically be linked to the image field and display the image. But this is not possible now. So, i have decided to just display the image in an image control.from my understanding, 1. retrieve image from database and convert it to temporary image file in a file path. 2. use the image control's imageurl to point to the file....

Can I display an image without getting the image from a URL?
From what I've read, it appears you can take an image and create a thumbnail of it with the result being a type 'image'. However, a search of dozens of sites suggests (hopefully this isn't true) that one always uses the URL of an image file to get the image to a control--meaning I can't just use the image created from the workup of an original image. I'm posting the demo code I'm trying, hoping that maybe I'm missing one or two easy steps.    Dim FullImage As Image = Image.FromFile("C:\temp\Picture1.jpg") ...

Web resources about - Getting images from db and displaying in WebControls.Image -

Request a demo - Connexus Support

SEO Blog - Search Engine Optimisation / Search Engine Marketing & general IT blog
Read the AKA Marketing search engine optimisation blog for posts about the latest organic search engine optimisation and search engine marketing ...

ALSEDI Group. Excellent Software. Excellent Usability.
ALSEDI Group Portal. High quality Surveillance, Privacy Protection and Desktop Enhancement software.

Case insensitive compare on string in ASP.NET - Coders Grid
using System ; using System.Collections.Generic ; using System.Linq ; using System.Web ; using System.Web.UI ; using System.Web.UI.WebControls ...

Hong Kong 繁体中文 / English China 简体中文 United States English Canada Francais / English Central-South America & Caribbean Region English / Espanol ...

Copyright Information - Media Temple
The (mt) Media Temple ( web site, including all text, HTML, scripts, and images are copyright 1998-2014. All rights reserved. ...

New Microsoft DevRadio Episode: World of Warcraft API Starter Kit for Windows Phone
This is the blog of Dave Isbitski. A Technology Evangelist for Microsoft based out of Philadelphia, PA USA. He is currently focused on helping ...

Adventures in Worstpracticeville
This morning, I wrote ~4500 lines of code in about two minutes. Skeptical? I thought you would be, so here's the curious tale of how I deviated ...

ConditionalRequiredTextValidator Control
The ConditionalRequiredTextValidator control allows you to specify a CheckBox, RadioButton, CheckBoxList, RadioButtonList, DropDownList, or ListBox ...

IT Managed Service Providers with Datacenters in India - Netmagic
As a leading Managed service provider with datacenters in India, Netmagic solutions, fulfills your entire IT infrastructure requirements: from ...

Resources last updated: 1/21/2016 9:24:01 AM