Bind database image to the ad rotator control
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 bi开发者_开发问答nd the image to the adrotator.
please help. Thanks in advance.
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 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).
精彩评论