Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1042543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:31:31+00:00 2026-05-16T15:31:31+00:00

I have a generic handler public void ProcessRequest(HttpContext context) { context.Response.ContentType = image/jpeg,png,jpg,gif; int

  • 0

I have a generic handler

public void ProcessRequest(HttpContext context)
    {

        context.Response.ContentType = "image/jpeg,png,jpg,gif";
        int newsId = int.Parse(context.Session["newsId"].ToString());
        int FK_UnitId = int.Parse(context.Session["UserData"].ToString());
        Managers.Photo p = new Managers.Photo();
        string dirPath = ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsImages" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId.ToString() + "/";
        string dirPathForTextFiles = ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsTextFiles" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId + "/";
        DataTable dt = p.GetAllPhotos(newsId);
        List<string> l = new List<string>(dt.Rows.Count);
        byte[] b = null;
        FileStream f;
        try
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                l.Add(dirPath + dt.Rows[i]["photoName"].ToString());
                f = new FileStream(l[i].ToString(), FileMode.Open, FileAccess.ReadWrite);
                b = new byte[f.Length];
                f.Read(b, 0, b.Length);
                context.Response.OutputStream.Write(b, 0, b.Length);
                context.ClearError();
                f = null;
                b = null;

            }
        }
        catch (IOException e)
        {
           string message =  e.Message;
        }


    }

and a list view on my page: the .cs file contains

Session.Add("newsId", newsId);  
string dirPath =ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsImages" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId + "/";  
string dirPathForTextFiles =ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsTextFiles" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId + "/";  
DataTable dt = p.GetAllPhotos(int.Parse(newsId));  
List<string> l = new List<string>(dt.Rows.Count);  
for (int i = 0; i < dt.Rows.Count; i++)  
{  
    l.Add(dirPath + dt.Rows[i]["photoName"].ToString());  
}  
lv_showImages.DataSource = l;  
lv_showImages.DataBind();

my source

<asp:ListView ID="lv_showImages" GroupItemCount="4" runat="server">
    <ItemTemplate>
         <asp:Image ID="img_newsImage" Height="100px" Width="100px" runat="server ImageUrl ='<%# "RetreiveImage.ashx" %>' />
   </ItemTemplate>  
</asp:ListView>`

Now my problem:

When the list has more than one path to set of images, only the first image has appeared and repeated, although I debug my handler and I find that length of b the byte array differs in the loop and this means that it is supposed to write different images rather than repeat the first image by the number of images, I don’t know why the first image only appeared.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:31:32+00:00Added an answer on May 16, 2026 at 3:31 pm

    I don’t think you can return multiple images in a single request. I’m guessing that you are writing the contents of all of your images to the response but the browser only reads up to the end of the first image. You will have to change your handler to accept an image identifier parameter and return only that image.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have declared a generic event handler public delegate void EventHandler(); to which I
I have generic type that looks like: public class GenericClass<T, U> where T :
I have a generic linked-list that holds data of type void* I am trying
I have made a generic handler (.ashx) to fetch some database values using jquery
i have a handler for download files like below : using System; using System.Collections.Generic;
I have a Generic HTTP Handler (*.ashx) in my ASP.Net application which performs some
I have the following code public abstract class Event { public void fire(Object... args)
In Structure map I have the following line working with domain events: public void
I have generic list which must be a preserved order so I can retrieve
I want to write in Delphi (2009 - so I have generic dictionary class)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.