Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Populate image from db

Reply
Thread Tools

Populate image from db

 
 
DavidC
Guest
Posts: n/a
 
      02-03-2010
I have small images stored in a SQL table as varbinary(max). How do I load
that stored image into an asp.net Image control...or should I use something
different? I only found an ImageUrl property but that refers to a file path.
Any help is appreciated. Thanks.
--
David
 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      02-03-2010
On Feb 3, 11:26*pm, DavidC <dlch...@lifetimeinc.com> wrote:
> I have small images stored in a SQL table as varbinary(max). *How do I load
> that stored image into an asp.net Image control...or should I use something
> different? *I only found an ImageUrl property but that refers to a file path.
> *Any help is appreciated. *Thanks.
> --
> David


Use ASHX generic handler

<img src="image.ashx">

Let me know if I should help with the code for ashx
 
Reply With Quote
 
 
 
 
DavidC
Guest
Posts: n/a
 
      02-04-2010
Yes, please. I am not familiar with ashx. Thanks.
--
David


"Alexey Smirnov" wrote:

> On Feb 3, 11:26 pm, DavidC <dlch...@lifetimeinc.com> wrote:
> > I have small images stored in a SQL table as varbinary(max). How do I load
> > that stored image into an asp.net Image control...or should I use something
> > different? I only found an ImageUrl property but that refers to a file path.
> > Any help is appreciated. Thanks.
> > --
> > David

>
> Use ASHX generic handler
>
> <img src="image.ashx">
>
> Let me know if I should help with the code for ashx
> .
>

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      02-04-2010
On Feb 4, 2:46*pm, DavidC <dlch...@lifetimeinc.com> wrote:
> Yes, please. I am not familiar with ashx. Thanks.
> --
> David
>
>
>
> "Alexey Smirnov" wrote:
> > On Feb 3, 11:26 pm, DavidC <dlch...@lifetimeinc.com> wrote:
> > > I have small images stored in a SQL table as varbinary(max). *How do I load
> > > that stored image into an asp.net Image control...or should I use something
> > > different? *I only found an ImageUrl property but that refers to a file path.
> > > *Any help is appreciated. *Thanks.
> > > --
> > > David

>
> > Use ASHX generic handler

>
> > <img src="image.ashx">

>
> > Let me know if I should help with the code for ashx
> > .- Hide quoted text -

>
> - Show quoted text -


it must be something like this

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
GetFromDb();
}

private void GetFromDb()
{

..... your database code here ....

byte[] content = (byte[])db.ExecuteScalar(sql);

HttpContext.Current.Response.ContentType = "image/jpeg";
HttpContext.Current.Response.BinaryWrite(content);

}

public bool IsReusable
{
get
{
return false;
}
}

}

Add new ashx to your project and copy the code into it.

When it works, you will be able to get an image as http://yoursite/image.ashx
 
Reply With Quote
 
DavidC
Guest
Posts: n/a
 
      02-04-2010
Thanks. Now I just have to convert your C# to VB.
--
David


"Alexey Smirnov" wrote:

> On Feb 4, 2:46 pm, DavidC <dlch...@lifetimeinc.com> wrote:
> > Yes, please. I am not familiar with ashx. Thanks.
> > --
> > David
> >
> >
> >
> > "Alexey Smirnov" wrote:
> > > On Feb 3, 11:26 pm, DavidC <dlch...@lifetimeinc.com> wrote:
> > > > I have small images stored in a SQL table as varbinary(max). How do I load
> > > > that stored image into an asp.net Image control...or should I use something
> > > > different? I only found an ImageUrl property but that refers to a file path.
> > > > Any help is appreciated. Thanks.
> > > > --
> > > > David

> >
> > > Use ASHX generic handler

> >
> > > <img src="image.ashx">

> >
> > > Let me know if I should help with the code for ashx
> > > .- Hide quoted text -

> >
> > - Show quoted text -

>
> it must be something like this
>
> [WebService(Namespace = "http://tempuri.org/")]
> [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
> public class ImageHandler : IHttpHandler
> {
> public void ProcessRequest(HttpContext context)
> {
> GetFromDb();
> }
>
> private void GetFromDb()
> {
>
> ..... your database code here ....
>
> byte[] content = (byte[])db.ExecuteScalar(sql);
>
> HttpContext.Current.Response.ContentType = "image/jpeg";
> HttpContext.Current.Response.BinaryWrite(content);
>
> }
>
> public bool IsReusable
> {
> get
> {
> return false;
> }
> }
>
> }
>
> Add new ashx to your project and copy the code into it.
>
> When it works, you will be able to get an image as http://yoursite/image.ashx
> .
>

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      02-04-2010
On Feb 4, 6:49*pm, DavidC <dlch...@lifetimeinc.com> wrote:
> Thanks. Now I just have to convert your C# to VB.
> --
> David
>
>
>
> "Alexey Smirnov" wrote:
> > On Feb 4, 2:46 pm, DavidC <dlch...@lifetimeinc.com> wrote:
> > > Yes, please. I am not familiar with ashx. Thanks.
> > > --
> > > David

>
> > > "Alexey Smirnov" wrote:
> > > > On Feb 3, 11:26 pm, DavidC <dlch...@lifetimeinc.com> wrote:
> > > > > I have small images stored in a SQL table as varbinary(max). *How do I load
> > > > > that stored image into an asp.net Image control...or should I use something
> > > > > different? *I only found an ImageUrl property but that refers to a file path.
> > > > > *Any help is appreciated. *Thanks.
> > > > > --
> > > > > David

>
> > > > Use ASHX generic handler

>
> > > > <img src="image.ashx">

>
> > > > Let me know if I should help with the code for ashx
> > > > .- Hide quoted text -

>
> > > - Show quoted text -

>
> > it must be something like this

>
> > [WebService(Namespace = "http://tempuri.org/")]
> > [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
> > public class ImageHandler : IHttpHandler
> > {
> > public void ProcessRequest(HttpContext context)
> > {
> > GetFromDb();
> > }

>
> > private void GetFromDb()
> > {

>
> > ..... your database code here ....

>
> > byte[] content = (byte[])db.ExecuteScalar(sql);

>
> > HttpContext.Current.Response.ContentType = "image/jpeg";
> > HttpContext.Current.Response.BinaryWrite(content);

>
> > }

>
> > public bool IsReusable
> > {
> > get
> > {
> > return false;
> > }
> > }

>
> > }

>
> > Add new ashx to your project and copy the code into it.

>
> > When it works, you will be able to get an image ashttp://yoursite/image..ashx
> > .- Hide quoted text -

>
> - Show quoted text -


Here's more on VB
http://msdn.microsoft.com/en-us/library/ms228090.aspx

Have fun!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
EAP type list doesn't populate with anything =?Utf-8?B?Z3MzMDBib2k=?= Wireless Networking 0 07-11-2005 08:51 PM
populate one list box with selected values from another list box steven.cooper@infocision.com ASP .Net 1 03-12-2005 11:29 PM
Populate a popup window with clickable records from an Access DB and upon clicking, populate a selectbox on the original webpage with the clicked record Enjoy Life ASP General 2 02-23-2005 10:48 PM
wx.Image: Couldn't add an image to the image list. Laszlo Zsolt Nagy Python 1 01-26-2005 09:55 PM
How to populate a checkbox from a database Lamine Darbouche ASP .Net 1 02-16-2004 02:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57