Microsoft KB Archive/196080

= PRB: ReadFromFile Fails for Attachment of Type CdoOle =

Article ID: 196080

Article Last Modified on 3/4/2004

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.1
 * Microsoft Collaboration Data Objects 1.2
 * Microsoft Collaboration Data Objects 1.21

-



This article was previously published under Q196080



SYMPTOMS
If a bitmap attachment has the type CdoOLE, the attachment can be written to a file on disk with the WriteToFile method without an error occurring. However, when you try to use the ReadFromFile method of an attachment object to read a bitmap file from the disk into a message where CdoOLE is the attachment type, you will get one of the following error messages, depending on the version of CDO (1.1, 1.2, 1.21):

Run-time error '-2147221233 (8004010f)'

[Collaboration Data Objects - [MAPI_E_NOT_FOUND (8004010F)]]

- or -

Run-time error '-2147467259(80004005)'

[Collaboration Data Objects - [E_FAIL(8000405)]]

The code provided in the "More Information" section below illustrates that the error will occur even if you have previously written the file from an Attachment object with the WriteToFile method.



CAUSE
Bitmap files are not in OLE docfile format. If the Type property of the Attachment object is CdoOLE, the file specified in the ReadFromFile method must be in OLE docfile format. The term "OLE docfile" indicates that the file is written by an application such as Microsoft Word version 6.0 or later that writes files using the OLE IStorage and IStream interfaces.



RESOLUTION
Specify CdoFileData (1) for the Type property of the Attachment or use Microsoft Outlook to insert the bitmap.



STATUS
This behavior is by design. CDO (1.1, 1.2, 1.21) documenation states that the CdoOle file must be an OLE Doc file, not just a OLE file.



Steps to Reproduce Behavior
 Open the Microsoft Paint accessory and draw something. Save it as "Test.bmp" in a folder, for example "C:\Temp". In a new message in Outlook, select Object from the Insert menu. Select "Create from file" to insert your picture "Test.bmp" into the newly-created message. Send the newly-created message to yourself (or someone else). Make sure the message received from the above steps is the first message in your Inbox. (This is because the code below will only test the first message in the Inbox.) Create a Visual Basic project and put a button on the form.</li> Add Microsoft CDO (1.1, 1.2, 1.21) to the Project References.</li>  Paste the code below into the project. ' The code below assumes a reference to the CDO (1.1, 1.2, 1.21) ' Library. However if you are using CDO (1.1), then you must ' change the name of the Cdo_PR_ATTACH_NAME constant to instead ' be ActMsgPR_ATTACH_NAME '    Option Explicit

Dim objSession As MAPI.Session Dim myMsg As MAPI.Message Dim newMsg As MAPI.Message Dim myAttach As MAPI.Attachment Dim newAttach As MAPI.Attachment

Private Sub Command1_Click

Set objSession = CreateObject("MAPI.Session") objSession.Logon MsgBox "CDO version = " & objSession.Version

Set myMsg = objSession.Inbox.Messages.GetFirst 'MsgBox "myMsg.Subject is: " & myMsg.Subject

Set myAttach = myMsg.Attachments.Item(1) 'MsgBox "Attach Name is : " & myAttach.Name 'MsgBox "Attach Type is : " & myAttach.Type 'MsgBox "Attach Class is : " & myAttach.Class 'MsgBox "Attach Method is : " & myAttach.Fields(CdoPR_ATTACH_METHOD)

myAttach.WriteToFile "C:\temp\attach.bmp"

Set newMsg = objSession.Outbox.Messages.Add newMsg.Subject = "Re: " & myMsg.Subject newMsg.Text = "Re: " & myMsg.Text

Set newAttach = newMsg.Attachments.Add newAttach.Name = "attach.bmp" newAttach.Type = myAttach.Type newAttach.Position = myAttach.Position

newAttach.ReadFromFile "C:\temp\attach.bmp"

newMsg.Update objSession.Logoff End Sub </li> Run the code.</li>  The following line will generate one of the messages described in the preceding Symptoms section. newAttach.ReadFromFile "C:\temp\attach.bmp" </li></ol>

To prevent the error message, you may change the following line of code: newAttach.Type = myAttach.Type to newAttach.Type = CdoFileData     'For CDO (1.2 or 1.21) or: newattach.Type = ActMsgFileData  'For CDO (1.1)

Keywords: kbmsg kbprb KB196080

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.