none
Get Ole Object From Ole Field in Access 2000 RRS feed

  • Question

  • So far I've found a lot of useless answers as to how to retrieve an image stored as an ole objetct and save it to the file system. The Problem is I don't know What kind of format it's stored in, so I don't know the size of the header. Help?
    Thursday, January 12, 2012 8:24 PM

Answers

  • Unfortunately this is quite problematic since you actually need to know which application was used to saved the file to the database. So, even if you know the file type it may not be enough information for stripping the OLE header from the binary stream.

    If Object Linking and Embedding was not used, but instead a binary stream was saved to database then it wouldn't be very difficult to extract, knowing the type of file of course.

    BTW, if you open the database in Microsoft Access and view the table where the data is stored, it should be possible to double-click on the column to display it in a compatible application (assuming it's installed).


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Friday, January 13, 2012 6:50 PM

All replies

  • I am afraid that is not possible to determine the size of file header (which includes the file's type, and a variable length string for the original location of the file) using ADO.Net. The header is implementation detail of Access, and is not exposed from its database drivers. 

    If you can force some Access versions on to your customers, you can reverse engineer Access's header data size for that version only. Anytime the Access team releases an update your code needs to be tested again, as the implementation detail can change.

    Of course, if you indeed saved an image file to the field, you can search for the image header (e.g. "gif87a" or "gif89a") in the blob.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    Thursday, January 12, 2012 9:48 PM
  • Hello Jose,

    I would suggest adding a field to your database table which indicates the file type i.e. PNG, JPG, BMP etc of the Ole Object (binary data) so now when extracting binary data you now know the file type.


    KSG
    Friday, January 13, 2012 1:11 PM
  • Unfortunately this is quite problematic since you actually need to know which application was used to saved the file to the database. So, even if you know the file type it may not be enough information for stripping the OLE header from the binary stream.

    If Object Linking and Embedding was not used, but instead a binary stream was saved to database then it wouldn't be very difficult to extract, knowing the type of file of course.

    BTW, if you open the database in Microsoft Access and view the table where the data is stored, it should be possible to double-click on the column to display it in a compatible application (assuming it's installed).


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Friday, January 13, 2012 6:50 PM
  • Unfortunately this is quite problematic since you actually need to know which application was used to saved the file to the database. So, even if you know the file type it may not be enough information for stripping the OLE header from the binary stream.

    If Object Linking and Embedding was not used, but instead a binary stream was saved to database then it wouldn't be very difficult to extract, knowing the type of file of course.

    BTW, if you open the database in Microsoft Access and view the table where the data is stored, it should be possible to double-click on the column to display it in a compatible application (assuming it's installed).


    Paul ~~~~ Microsoft MVP (Visual Basic)


    I agree although the code (taken from a larger section of code) shown below is how I have obtained binary data from a MS-Access table where the column type was OLE Object and stored custom file types

    Dim BlobColum As Integer = 2
    Dim Extension As String = ".bmp"
    Dim FileName As String = "C:\Data\"
    
    If Not IsDBNull(dr.Item(BlobColum)) Then
        Dim bt() As Byte = CType(dr.Item(BlobColum), Byte())
        Dim ms As IO.MemoryStream = New IO.MemoryStream(bt)
    
        PathAndName = FileName & ItemNumber.ToString & Extension
    
        Dim fs As IO.FileStream = New IO.FileStream(PathAndName, _ 
            IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
        Dim Writer As IO.BinaryWriter = New IO.BinaryWriter(fs)
    
        Writer.Write(bt)
        Writer.Flush()
        Writer.Close()
        fs.Close()
        Writer = Nothing
        fs.Dispose()
    End If
    
    


     


    KSG
    Saturday, January 14, 2012 5:19 AM
  • Hi,

    I am writing to check the status of the issue on your side.Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know.I will be more than happy to be of assistance.

    Have a nice day


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 18, 2012 2:56 AM
    Moderator
  • Yeah, getting the binary stream value isn't really a problem, but separating the content from the OLE header is. That is, unless you know what application was used to save it.


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Wednesday, January 18, 2012 3:25 PM
  • Was puzzled for a long time, respectfully waiting for your results.
    BMP files have the results, in the msdn. Which have to define a structure.

     

    HOWTO: Retrieving Bitmap from Access and Displaying In Web Page

          Type OBJECTHEADER

            Signature As Integer

            HeaderSize As Integer

            ObjectType As Long

            NameLen As Integer

            ClassLen As Integer

            NameOffset As Integer

            ClassOffset As Integer

            ObjectSize As PT

            OleInfo As String * 256

          End Type

    Monday, February 6, 2012 8:28 AM