Extracting OLE Object from MS Access

Hello,
I'm using MS Access as database back-end for my C# application and I have an OLE Object field in my MS Access Database and I want to extract the content (say JPG image) to the users' desktop.
I'm using OleDB and C#.NET 2.0.
How can I do that
Thanks.


Answer this question

Extracting OLE Object from MS Access

  • Brannon

    I also got the Parameter not valid error. What I had to do was change the offset to a different number. Such as 135 for one image and 190 for another. That 78 only works for that one image.


  • Laurent.Guinnard

    Hi,

    Currently I am also facing the same issue. However, in my case, the Ole object field can contain any file: Word, Exce, Jpeg, Bmp, Gif, html, etc. Morever, the solution provided above is not working for me. I get the "Parameter not valid error" while initializing the Bitmap object.

    Thanks in advance for any help.

    Cheers,

    Narinder


  • MagedSalah

    THANK YOU very much :)
    What about extracting an html file
    Thanks.

  • SamuelEe

    Here is how you can extract an image from an access database. In the northwind database the image is offset 78 bits.



    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.OleDb;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Text;
    using System.IO;
    using System.Windows.Forms;
    namespace OleImages
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
    String strConn = @"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = C:\Nwind.mdb;";
    OleDbConnection conn = new OleDbConnection(strConn);
    Byte[] byPicture;
    String strCmd = "Select Picture From Categories where CategoryID=1";
    OleDbCommand cmd = new OleDbCommand(strCmd, conn);
    try
    {
    conn.Open();
    byPicture = (Byte[]) cmd.ExecuteScalar();
    conn.Close();
    MemoryStream ms = new MemoryStream();
    Bitmap bm;
    ms.Write(byPicture, 78, byPicture.Length - 78);
    bm = new Bitmap(ms);
    pictureBox1.Image = bm;
    String strPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\test.jpg";
    bm.Save(strPath, ImageFormat.Jpeg);
    }
    catch
    {

    }
    }
    }
    }



  • Extracting OLE Object from MS Access