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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:15:04+00:00 2026-05-30T20:15:04+00:00

i am developing a web application in that i need to store image files

  • 0

i am developing a web application in that i need to store image files and some other documents in a database and then i have to show them on a web page in an image box preferably. i have stored images in database and also PDF files in the form of byte array and i used a Generic Handler to get byte array from database and then show them in a image box it works fine for the images but it does not work with PDF files.

public class ShowImage : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    { 
        Int32 imgID;
        if (context.Request.QueryString["id"] != null)
            imgID = Convert.ToInt32(context.Request.QueryString["id"]);
        else
            throw new ArgumentException("No parameter specified");

        context.Response.ContentType = "image/jpeg";
        byte[] buffer = ShowEmpImage(imgID);
        context.Response.BinaryWrite(buffer);
    }

    public Stream ShowEmpImage(int empno)
    {
        dbClass db = new dbClass();
        string sql = "SELECT imgfile FROM myFiles WHERE id = @ID";
        SqlCommand cmd = new SqlCommand(sql, db.con);
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@ID", empno);
        object img = null;
        try
        {
            db.Connect();
            img = cmd.ExecuteScalar();
        }
        catch
        {
            return null;
        }
        finally
        {
            db.Disconnect();
        }
        return new MemoryStream((byte[])img);
    }

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

please guide me how can i show PDF files and some other files to the image box? actually the problem is my application runs with the existing application and that have no way to store extensions of files so the only way i can show files is “show them in as a image” but if their is a better way then help me out friends.

  • 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-30T20:15:05+00:00Added an answer on May 30, 2026 at 8:15 pm

    There’s a reason that PDF doesn’t work when representing it as an image… it isn’t an image. Additionally, claiming it is "image/jpeg" is going to make it pretty broken unless the browser does explicit file-header checking, and really need fixing IMO. If you don’t currently store the file name / extension / MIME / something then frankly: that’s a problem you need to fix.

    For displaying a PDF, I suspect you’d need to use an <iframe> rather than an <img>, which a: might not work on all browsers, and b: might not be very convenient to the caller. Personally I’d just offer a download link (and in the handler, use content-disposition to tell the browser to treat it as a download).

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

Sidebar

Related Questions

I'm developing an iPhone application. The application access some web service that aboug other
I'm developing a web application that shows some controls and descriptions dynamically (I don't
I am currently developing a web application that receives data from an on-site database.
I'm developing an internal web application, that allows me to store remote control credentials
We are developing an ASP.Net web application and need that application to work properly
I am developing a web application that can support threaded comments. I need the
I'm developing a Web application. I need to display some decimal data correctly so
I'm developing an web application that uses a non-relational database as a backend (django-nonrel
I'm developing a web application that will need to be localized to English and
I'm developing a web application that opens a popup using windows.open(..). I need to

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.