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.

Extracting OLE Object from MS Access
Brannon
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
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
{
}
}
}
}