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 6096997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:59:32+00:00 2026-05-23T12:59:32+00:00

I m using a handler to display images on my page from database public

  • 0

I m using a handler to display images on my page from database

public void ProcessRequest (HttpContext context)
{
    SqlConnection con = new SqlConnection();
    con.ConnectionString = ConfigurationManager.ConnectionStrings["XYZ"].ConnectionString;
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "Select Image from EmployeeInfo where Emp_Id = @ID";
    cmd.CommandType = CommandType.Text;
    cmd.Connection = con;

    SqlParameter ImageID = new SqlParameter("@ID", System.Data.SqlDbType.Int);
    ImageID.Value = context.Request.QueryString["ID"];
    int height = Convert.ToInt32(context.Request.QueryString["Ht"]);
    int width = Convert.ToInt32(context.Request.QueryString["Wt"]);
    cmd.Parameters.Add(ImageID);
    con.Open();
    SqlDataReader dReader = cmd.ExecuteReader();

    if (dReader.HasRows)
    {
        dReader.Read();
        byte[] imagethumbnail = null;
        try
        {
            imagethumbnail = MakeThumbnail((byte[])dReader["Image"], width, height);
        }
        catch
        {             
        }
        context.Response.BinaryWrite(imagethumbnail);        
    }
    dReader.Close();
    con.Close();
}

public static byte[] MakeThumbnail(byte[] myImage, int thumbWidth, int thumbHeight)
{
    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
    using (Image thumbnail = Image.FromStream(new MemoryStream(myImage)).GetThumbnailImage(thumbWidth, thumbHeight, null, new IntPtr()))
    {
        thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        return ms.ToArray();
    }
}

This code works fine when displaying images from database.
Now What I want to do is to Show image preview using a different Handler.
Now if u look at the above code then you can see we have image data in byte[] form.
I m uploading a image and I m able to get the data in byte[] but this data of mine is on .cs page.

context.Response.BinaryWrite(imagethumbnail);

If I use this command converting data into bytes from page, it shows me the image on page nothing else.
Can you give me any idea how to show this data into image?

There is nothing much change in the datastream
This is what I want to use but how to get byte[] from .cs page to handler.

 imagethumbnail = MakeThumbnail((byte[])dReader["Image"], width, height);
        context.Response.BinaryWrite(imagethumbnail);
  • 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-23T12:59:32+00:00Added an answer on May 23, 2026 at 12:59 pm

    You can seperate your database image logic into a Generic Handler (ASHX) and then use the handler as your image’s src e.g.

    <img src="GetImage.ashx?id=1"/>
    

    You’d need to create GetImage.ashx and handle your id’s (or whatever your using) appropriately. Then you can do a simple write back to the page.

    This will allow you to dynamically pull an image from the database while using it as a seperate element on your page.

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

Sidebar

Related Questions

I have an ASHX handler that I am using to display images that are
I'm using spring and hibernate to display an extjs chart from database. But, when
i'm trying to display an image from the database in an ASP.NET web page.
I was writing a database handler class in PHP using the mysqli class and
Is it advisable to use a handler to display Images ? the issue is
I'm trying to display an image file from a directory using a PHP echo
I am trying to disable log rotation, for file handler using, FileHandler fh =
When manipulating Handler Mappings using the Microsoft.Web.Administration namespace, is there a way to remove
I'm using an error handler on my main calling procedure and letting the other
I'm using code in the Application_BeingRequest() handler of my Global.asax to do some very

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.