Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Visio OLE embedded in Access DB

20 views
Skip to first unread message

gsauns

unread,
May 17, 2011, 3:43:50 PM5/17/11
to
I have several Access MDB files that contain a table with a field that
contains an embedded Visio drawing.

I need to loop thru selected files, extract the embedded Visio object,
and save it out to a JPG.

This would be easy enough through automation if I could get that Visio
object opened in a Visio.ApplicationClass. But, I can't due to the
fact that it's embedded in the database. Does anyone have any ideas? I
am able to read it into my DataTable as a byte array, but when I tried
to use a FileStream and open the file, Visio did not like the
resultant file.

I'm using Visio 2010 (14.0 assembly).

My code thus far:
OleDbConnection conn = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Y:
\myfile.mdb;Persist Security Info=False;");

OleDbCommand cmd = new OleDbCommand("SELECT OLEFile FROM MyTable",
conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new System.Data.DataTable();

visioByteArray = (byte[])dt.Rows[0]["OLEFile"];

FileStream fs = new FileStream(Environment.CurrentDirectory +
@"\abc.vsd", FileMode.OpenOrCreate, FileAccess.ReadWrite);

fs.Write(visioByteArray, 0, visioByteArray.);
fs.Close();
// This does produce a file but Visio does not recognize it.

gsauns

unread,
May 17, 2011, 4:33:20 PM5/17/11
to

I figured it out. For anyone that's curious...

When an object is embedded in Access as an OLE Object, Access adds an
OLE header to the file.
I put this stream out to a text file and compared it to a legit .VSD
file. I found the stuff that seemed like the header, figured out the
offset, and then replaced one of the lines above with:
int offset = 84; // For me, that was the offset
fs.Write(visioByteArray, offset, visioByteArray.Length - offset);

0 new messages