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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:31:46+00:00 2026-05-27T14:31:46+00:00

The project i am working on is basically having a module for comments. Users

  • 0

The project i am working on is basically having a module for comments. Users are able to post and posts are subjected to comments. I have already done most part but am stuck at the part where i need to load all images across all the posts and comments posted.

Each user’s profile picture ( thumbnail ) i want to be displayed beside his/her post. The images are stored in the database and NOT file system. I have tried a lot of ways, and none of it seem to work.

here is how i am retrieving the byte array (image data) from the db

TestDBDataContext context1 = new TestDBDataContext();

        var r = (from a in context1.ImageTables where a.Id == 8 select a).First();

        MemoryStream stream = new MemoryStream(r.FileImage.ToArray());

Method 1: (This does not work, for some reason it shows an invisible image which is having an extension of .aspx.jpeg and it appears corrupt)

an html image tag on the web form

<img src="WebForm1.aspx" alt="" />

code behind

 var r = (from a in db.ImageTables where a.Id == 17 select a).FirstOrDefault();
            if (r != null)
            {                    
                Response.ContentType = "image/jpeg";
                Response.BinaryWrite(r.FileImage.ToArray());
                return;
            }

Method 2
Trying to save the image as System.Drawing.Image object and than linking the image src to that. This way works, but there is no point in having the pics in the database if i cannot retrieve and display multiple images at once.

        TestDBDataContext context1 = new TestDBDataContext();

        var r = (from a in context1.ImageTables where a.Id == 8 select a).First();

        MemoryStream stream = new MemoryStream(r.FileImage.ToArray());

        System.Drawing.Image newImage;

        newImage = System.Drawing.Image.FromStream(stream);
        Random random = new Random();
        newImage.Save("D:\\" + random.Next(1000, 5000) + ".jpeg");

I hope you guys are willing to put me on the right track here ! thanks a lot !

  • 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-27T14:31:47+00:00Added an answer on May 27, 2026 at 2:31 pm

    Well in our case when we’re trying to display image that is being read from the database we usually create a HttpHandler and set the image like for example:

    Logo.ImageUrl = "~/Handlers/GetTempLogo.ashx?LogoGUID=" + Session["TempLogoGUID"];
    

    an in the handler we have:

    using (aDataContext db = new aDataContext())
                {
                    var objData = (from c in db.Companies where c.CompanyId == CompanyID select c.LogoSmall).FirstOrDefault();
                    if (objData == null)
                    {
                        context.Response.BinaryWrite(System.IO.File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/Images/defaultLogo.png")));
    
                        return;
                    }
                    using (System.IO.MemoryStream str = new System.IO.MemoryStream(objData.ToArray(), true))
                    {
                        str.Write(objData.ToArray(), 0, objData.ToArray().Length);
                        Byte[] bytes = str.ToArray();
                        context.Response.BinaryWrite(bytes);
                    }
                }
    

    Hope this gives you a hint.

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

Sidebar

Related Questions

I have a secret project I am working on and basically what it does
I´m working on a project that basically will show some data collected from hardware
The project I´m working on needs to auth its users against AD, and as
I have started using Linq to SQL for a project im working on and
I working on project and have problem with threading and update of UI. I
I'm working on android unity3d project where I want to post some stuff to
I'm working on a project at the moment and have become a little stuck.
I am working on a VSTO Excel project and I am having some troubles
I have been working on a project for a few months now and my
I have been trying to get xapian working django haystack for a project im

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.