Partager via


GetEncodedContentStream Method

Topic Last Modified: 2006-06-13

Returns the Microsoft® ActiveX® Data Objects (ADO) Stream object containing the body part content in encoded format.

Applies To

IBodyPart Interface

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In

CDOEX.DLL

Syntax

Function GetEncodedContentStream() As ADODB.Stream
HRESULT GetEncodedContentStream
(
        _Stream** pVal
);

Parameters

  • pVal
    Returned reference to a _Stream object.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

CDO uses the current value of the ContentTransferEncoding property to determine which encoding mechanism to use to decode or encode body part contents. CDO uses the encoding specified in ContentTransferEncoding to encode the contents. Although CDO provides standard defaults for ContentTransferEncoding, it is the programmer's responsibility to have the appropriate value set before calling GetEncodedContentStream.

The Stream object returned contains a read/write copy of the current (encoded) contents of the object implementing IBodyPart. If you modify the contents within the returned Stream object, you must call the Flush method to commit the changes back into the object.

The GetEncodedContentStream method returns an error if called on a multipart body part because these body parts have no content, and simply act as structure units in the Multipurpose Internet Mail Extensions (MIME) hierarchy.

To obtain the content in its decoded form, use the GetDecodedContentStream Method.

Example


' This is a manual way to copy an attachment.
Dim iMsg As New CDO.Message
Dim iBp As CDO.IBodyPart
Set iBp = iMsg.AddAttachment("c:\report.doc")
Dim Stm As ADODB.Stream
Set Stm = iBp.GetEncodedContentStream

Dim iMsg2 As New CDO.Message
Dim iBp2 As CDO.IBodyPart
Dim Flds As ADODB.Fields

Set iBp2 = iMsg2.BodyPart.AddBodyPart

Set Flds = iBp2.Fields
Flds("urn:schemas:mailheader:content-disposition") = "attachment"
Flds("urn:schemas:mailheader:content-transfer-encoding") = "base64"
Flds.Update

Dim Stm2 As ADODB.Stream
Set Stm2 = iBp2.GetEncodedContentStream
Stm.CopyTo Stm2
Stm2.Flush

' Go on to send messages.

' Clean up.
Stm.Close
Stm2.Close

Set Stm = Nothing
Set Stm2 = Nothing