Results 1 to 15 of 15

Thread: [RESOLVED] dynamically dispalying multiple images from database onto website.

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    50

    Resolved [RESOLVED] dynamically dispalying multiple images from database onto website.

    HeLLo everyone:

    I have a problem and hope you can help me. I'm attempting to dispaly MULTIPLE images from a SQL database onto a website and I'm using a combination of ASP.net and VB.net. Right now, it's just displaying one image. The website lets the user choose from a series of Articles, each article having Attachments (attachments being images). So, for example, if a user wants to know how to change his/her password, they select the article (article #907) and that particular article has four attachents (four images, stored in a different table), each image will basically walk the user through the process of changing the password. So, the number of images can dynamically change depending upon which article they choose.

    I really hope I didn't lose anyone there. Anyway, I have two different files. One is documenthandler.ashx (which is basically the getimage.asp), and then the main .asp website, which displays the image. Currently, the website is just displaying the first attachment. Here's the code:

    Documenthandler.ashx

    <%@ WebHandler Language="VB" Class="FileHandler" %>

    Imports System
    Imports System.Web
    Imports System.Data
    Imports System.Data.SqlClient

    Public Class FileHandler
    Implements IHttpHandler

    Const conString As String = "server/db"

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest


    Dim con As SqlConnection = New SqlConnection(conString)
    Dim cmd As SqlCommand = New SqlCommand("SELECT FileImage, FileType, filename FROM Attachments WHERE ArticleId=@ArticleId", con)
    cmd.Parameters.AddWithValue("@ArticleId", context.Request("ArticleId"))


    Using con
    con.Open()

    Dim myReader As SqlDataReader = cmd.ExecuteReader

    If myReader.Read() Then
    context.Response.Clear()
    context.Response.ClearContent()
    context.Response.ClearHeaders()

    Dim file() As Byte = CType(myReader("FileImage"), Byte())
    context.Response.ContentType = "application/octet-stream"
    context.Response.AddHeader("content-disposition", "attachment;filename=" + myReader("filename"))
    context.Response.BinaryWrite(file)

    End If
    End Using

    End Sub

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
    Get
    Return False
    End Get
    End Property

    End Class

    And then I have the image source tag on the main page:

    <asp:Image ID="image1" runat="server" ImageUrl='<%#Eval("Articleid", "~/Handlers/documenthandler-test.ashx?Articleid={0}")%>'/>

    And then, I attempt to retreive the SECOND image by replacing the 0 with a 1:

    <asp:Image ID="image1" runat="server" ImageUrl='<%#Eval("Articleid", "~/Handlers/documenthandler-test.ashx?Articleid={1}")%>'/>

    And I get this error message:

    Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

    If I can get the first image to show up, then I should be able to get the rest of them to show up. I've already tried to put in a loop and an array in the documenthandler.ashx page, and it still didn't work.

    Someone please help! Thanks!
    Last edited by webwiz082; Apr 9th, 2007 at 01:40 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width