Click here to Skip to main content
16,018,294 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear,

I have store image path in a database. Now i want to retrive particular image from database in image control on page load event.


I did the following codes for that. But Not working

1) In Page load i put

image.ImageUrl = dr("Image")
Not that dr("Image")="D:/abc.jpg"

2) I used Generic Handler, but this one is only working if the Binary image Store in database.


On Page Load


VB
image.ImageUrl = "Handler1.ashx"

The Name is Handler1.ashx


Public Class Handler1
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim LsM_Image As String
        LsM_Image = "D:\abc.jpg"

        'If (context.Session("ImageBytes")) IsNot Nothing Then
        'Dim image As Byte() = DirectCast(context.Session("ImageBytes"), Byte())
        context.Response.ContentType = "image/JPEG"
        'context.Response.BinaryWrite(image)
        'context.Handler.("D:\abc.jpg")
        context.Response.Pics("D:\abc.jpg")
        'End If

    End Sub

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
End Class
Posted
Updated 14-Mar-15 20:57pm
v2
Comments
Where is the issue exactly? Did you debug?

1 solution

D:/abc.jpg is at most a local! path, so how do you expect that a remote client will be able to display an image from that path? It is highly possible that the client has no any D: drive, or maybe your user has some smart-phone...
When you ant to share images in your web page you have to use some URL that can be accessed from anywhere, like this:
http://dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/logo250x135.gif
This is a link to the logo image of CP and can be seen from everywhere because http://dj9okeyxktdvd.cloudfront.net is a buplic URL, that resolves to the exact same place from everywhere, where D: is a local drive name that resolves to different path in every client...
 
Share this answer
 
Comments
basitsar 15-Mar-15 3:15am    
Dear,

I already save a path in database D:abc.jpg.
How i save through upload control. and save image in D:abc.jpg in server itself.
When going to retrieve it goes to server and then retrieve not in local.

thanks
Basit.
Kornfeld Eliyahu Peter 15-Mar-15 3:20am    
No! You are wrong. It may be stored in the D: drive of your server but the client knows nothing of the D: drive of your server...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900