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

  • Home
  • SEARCH
  • 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 850845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:19:56+00:00 2026-05-15T07:19:56+00:00

BACKGROUND: MS Access 2007 added an attachment field type, where images can be stored.

  • 0

BACKGROUND:
MS Access 2007 added an attachment field type, where images can be stored.
I am building a website using ASP.Net and the .NET framework 4

So, without using Silverlight, what is the easiest way to retrieve the image from the Access database on the server, and use as source for an Image control?

As a simple example:
In an ESL website for children, clicking on a “A”, would display an apple; “B” a bear, etc

NOTE: This is an A2007/A2010 attachment field, not a binary object

  • 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-15T07:19:57+00:00Added an answer on May 15, 2026 at 7:19 am

    You could read the image out of the database as a binary blob. This would be read out as a byte[] array. That byte[] could then be sent to the browser using a Response.BinaryWrite and a content-type of image/(type) – jpg/png/gif.

    The call would look something like:

    <img src="showmyimages.aspx?image=id" />
    

    And the code would look a little like:

    result = myWebService.GetImage(id);

    if (result != null) && result.Length > 0
    {
        Context.Response.ClearContent();
        Context.Response.ClearHeaders();
        Context.Response.ContentType = "image/gif";
        Context.Response.AddHeader("Content-Length", result.Length.ToString(System.Globalization.CultureInfo.CurrentCulture));
        Context.Response.AddHeader("content-disposition", String.Format("inline; filename={0}.gif", filename));
        Context.Response.BinaryWrite(result);
        Context.Response.End();
    }
    

    This disguises the filename of the image a little bit, but it allows the binary read directly from the database without having a permanent image on disk.

    EDIT:

    Everything I’ve read about the attachment field is that it stores as direct binary in the database just as it would if it were saving directly to a file. I haven’t attempted to write any code to this effect, but it is conceivable that no conversion is necessary if the binary data can be fed into a StreamReader, possibly even making use of WebResponse.GetResponseStream()

    EDIT:

    I was able to implement a handler using the following code that actually pulled the binary data from the attachment field (which can be verified in the debugger), however there appears to be an encoding involved that is not built in. The key seems to be the select statement that retrieves fldImage.FileData.

    public void ProcessRequest(HttpContext context)
            {
    
                string qry = "SELECT [Image], ID, [Images.Image.FileData] AS FileData, ";
                qry += "[Images.Image.FileName] AS FileName, [Images.Image.FileType] AS FileType";
                qry += " FROM Images WHERE (ID = 1)";
                string connect = @"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=##PathToDB##\Database1.accdb";
    
                using (OleDbConnection conn = new OleDbConnection(connect))
                {
                    if (context.Request.QueryString["id"] != null)
                    {
    
                        OleDbCommand cmd = new OleDbCommand(qry, conn);
                        cmd.Parameters.AddWithValue("ID", context.Request.QueryString["id"]);
                        conn.Open();
                        using (OleDbDataReader rdr = cmd.ExecuteReader())
                        {
                            if (rdr.HasRows)
                            {
                                rdr.Read();
                                context.Response.ClearContent();
                                context.Response.ClearHeaders(); 
                                context.Response.ContentType = "image/" + rdr["FileType"];
    
                                byte[] result = Encoding.UTF8.GetBytes(rdr["FileData"].ToString());
    
                                context.Response.AddHeader("Content-Length",
                                    result.Length.ToString(System.Globalization.CultureInfo.CurrentCulture)); 
                                context.Response.AddHeader("content-disposition", 
                                    String.Format("attachment; filename={0}", rdr["FileName"]));
                                context.Response.BinaryWrite(result);
                                context.Response.End();
                            }
                        }
                    }
                }
    
            }
    

    There are also some methods that are located in the Microsoft Office Interop library described at the MSDN Access Blog that may be of use. They describe loading and saving files, but it looks as if they may also be able to perform the same actions directly to stream objects. The reference is Microsoft.Office.Interop.Access.Dao. When adding it, go to the COM tab and look for Microsoft Office 12.0 Access Database Engine Objects Library. I haven’t tested this "straight to stream" theory.

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

Sidebar

Related Questions

Background info : I was handed a Tool, which was made using MS-Access 2007,
Background: I'm using a delegation technique to abstract access to arbitrary object methods, but
Background I work for a large organization which has thousands of MS Access applications
As usual, some background information first: Database A (Access database) - Holds a table
Background: At my company we are developing a bunch applications that are using the
Background I am writing and using a very simple CGI-based (Perl) content management tool
[SharePoint/MOSS 2007] I want to access several web services (on external sites, with WSDL
Background: I have a little video playing app with a UI inspired by the
Background: Some time ago, I built a system for recording and categorizing application crashes
Background: I need to reserve an amount of memory below 0xA0000 prior to my

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.