views:

25

answers:

1

Hi,

I am using asp.net 2.0 and C#.

I have a adrotator control, whcih I am binding to the database which has the three fields. AlternateText, ImageUrl and NavigateUrl.

Now, this works fine, as per the expectation. My question is this that the ImageUrl in the table contains a URL like http://www.xyz.com/abc.jpg but I want to store image in a database and then bind the image to the adrotator.

please help. Thanks in advance.

A: 

It sounds like you want to put the data of the image into a image field in the database. This can be achieved by reading the image from the web with a HttpWebRequest. You can then get the HttpWebResponse with :

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Then read the bytes from the response stream (See this SO question http://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream) . Then insert this byte[] into your database.

Then, you could use a custom handler to read the image from the database and output it as image/jpeg (or whatever mimetype you need).

Greg B