Saving Messages into ADO Stream Objects
Saving Messages into ADO Stream Objects
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.To save a serialized message from a Collaboration Data Objects (CDO) Message object to an ADO Stream object
- Retrieve the IDataSource interface on the Message object.
- Create or otherwise obtain a _Stream object reference on a Microsoft® ActiveX® Data Objects (ADO) Stream object.
- Use the IDataSource interface on the Message object to call OpenObject. Pass the _Stream object reference as the first argument, and the string "_Stream" as the second.
Visual Basic
' Reference to Microsoft ActiveX Data Objects 2.5 Library ' Reference to Microsoft CDO for Exchange 2000 Server Library ' Note: It is recommended that all input parameters be validated when they are ' first obtained from the user or user interface. Sub SaveMessageToFile(iMsg As CDO.Message, Filepath As String) Dim Stm As New Stream Stm.Open Stm.Type = adTypeText Stm.Charset = "US-ASCII" Dim iDsrc As IDataSource Set iDsrc = iMsg iDsrc.SaveToObject Stm, "_Stream" Stm.SaveToFile Filepath, adSaveCreateOverWrite End Sub
C++, IDL
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace #import "c:\program files\common files\microsoft shared\cdo\cdoex.dll" no_namespace // Note: It is recommended that all input parameters be validated when they are // first obtained from the user or user interface. void Save_Message_to_File(IMessagePtr iMsg, bstr_t filename) { /* ** This example shows a common use of the ADO Stream ** object with CDO, namely, saving a serialized ** message to disk using an ADO Stream object. **/ _StreamPtr pStm(__uuidof(Stream)); IDataSourcePtr iDsrc; iDsrc = iMsg; _variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR); pStm->raw_Open(varOptional, adModeUnknown, adOpenStreamUnspecified,NULL,NULL); pStm->Type = adTypeText; pStm->Charset = "US-ASCII"; // apparently, we need this! try { iDsrc->SaveToObject(pStm,_bstr_t("_Stream")); } catch(_com_error error) { throw error; } try { pStm->SaveToFile(filename,adSaveCreateOverWrite); } catch(_com_error e) { throw e; } }
VBScript
' Note: It is recommended that all input parameters be validated when they are ' first obtained from the user or user interface. Sub SaveMessageToFile(iMsg, Filepath) Dim Stm Set Stm = CreateObject("ADODB.Stream") Stm.Open Stm.Type = adTypeText ' 2 Stm.Charset = "US-ASCII" Dim iDsrc Set iDsrc = iMsg.DataSource iDsrc.SaveToObject Stm, "_Stream" Stm.SaveToFile Filepath, adSaveCreateOverWrite End Sub
Send us your feedback about the Microsoft Exchange Server 2003 SDK.
Build: June 2007 (2007.618.1)
© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.