Reading images from acess database and writing them to a disk

Posted on 2004-11-04
Last Modified: 2010-04-15
I have a table named Employees that has an Ole Column named Picture in MS Access 03.  I want to take that image (it has varying types such as .jpg and .bmp) read it from the database and write it to a folder named "Pictures" in the Application root directoy.  How do I do this?  
Question by:CDFA_Inc
    LVL 20

    Expert Comment

    Open a connection to the database, create a command with a text like SELECT PIC FROM TABLE and execute it using XxxDataReader reader = command.ExecuteReader() method (Xxx is OleDb or ODBC, depending on your connection). Then go over the results using while (reader.Read()) and read the picture using the method

    byte[] image = reader.GetValue(0) as byte[];

    Then if image is != null, save it to a file in the folder you want.

    Author Comment

    I understand the conversions.  I am curious as to how to write the byte array to file.  First of all the pictures in the database are of varying types.  How do you account for the title and extension of the pics.  Please post an example.
    LVL 20

    Accepted Solution

    The fact that you pictures have different types means that you have to read the data and examine it to find out what kind of file this is. Every picture file type has a specific structure, so if you know there will be JPEG and BMP files, you should check if the format is what JPEG expects and if not check for BMP. You can find more info about the file formats online, using google. The application AcdSee succeeds to do this - make a test by changing the extention of a JPEG to BMP and see that AcdSee will still show that the file is a JPEG file.

    This is a link how to write byte array to a file. There are some additional links about file operations on this page:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now