(My initial answer to this question was misleading. It worked fine for PDF files that were subsequently opened using Adobe Reader, but it did not always work correctly for other types of files. The following is the corrected version.)
Unfortunately, we cannot directly get the contents of the file in the Access Attachment field using OleDb. The Database Access Engine adds some metadata to the binary contents of the file, and this metadata is included if we get .FileData through OleDb.
To illustrate, a document called “Document1.pdf” is saved in the “Attachment” field using a user access interface. The beginning of this PDF file looks like this:

If we use the following code to try to extract the PDF file to disk
using (OleDbCommand cmd = new OleDbCommand()) { cmd.Connection = con; cmd.CommandText = "SELECT Attachments.FileData " + "FROM AttachTest " + "WHERE Attachments.FileName='Document1.pdf'"; using (OleDbDataReader rdr = cmd.ExecuteReader()) { rdr.Read(); byte[] fileData = (byte[])rdr[0]; using (var fs = new FileStream( @"C:\Users\Gord\Desktop\FromFileData.pdf", FileMode.Create, FileAccess.Write)) { fs.Write(fileData, 0, fileData.Length); fs.Close(); } } }
then the resulting file will contain metadata at the beginning of the file (in this case, 20 bytes)

Adobe Reader can open this file because it is strong enough to ignore any "junk file" that may appear in the file before the signature "% PDF-1.4". Unfortunately, not all file formats and applications forgive extraneous bytes at the beginning of the file.
Only official and commercial; The way to extract files from the Attachment field in Access is to use the .SaveToFile method of the ACE DAO Field2 , for example:
Note that if you try to use the .Value of the Field2 object, you will still get metadata at the beginning of the byte sequence; the .SaveToFile process is what robs it.
source share