This documentation is archived and is not being maintained.

SaveTo Method

Exchange Server 2003

SaveTo Method

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.

Binds to and saves data into the item with the specified URL.

Applies To

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In



        [Visual Basic]Function SaveTo
    SourceURL As String,     [ActiveConnection As Object],     [Mode As ConnectModeEnum],     [CreateOptions As RecordOpenOptionsEnum],     [Options As RecordOpenOptionsEnum],     [Username As String],     [Password As String],     [UserName As String]

        [C++]HRESULT SaveTo
    BSTR SourceURL,
    ConnectModeEnum Mode,
    RecordOpenOptionsEnum CreateOptions,
    RecordOpenOptionsEnum Options,
    BSTR Username,
    BSTR Password,
    BSTR UserName


The URL specifying where to save.
A reference to an existing Microsoft ActiveX Data Objects (ADO) Connection object to use when saving. A new Connection (session) object is implicitly created if none is specified.
ADO defined access mode for the object. This value is always ORed with adModeReadWrite. That is, at least read-write access is required to save the item.
Creation options for the new item. The values adFailIfNotExists and adOpenIfExists should not be used. If used, an E_INVALIDARG exception is raised.
This specifies options flag(s) opening the source. Your setting is always ORed with adOpenSource.
Used to pass a user name if needed for authentication.
Used to pass a password if needed for authentication.

Return Value

Returns S_OK if successful, or an error value otherwise.


The specified URL must identify a valid URL namespace that the OLE DB 2.5 root binder can resolve to a registered provider binder. When resolved, the URL must conform to that provider binder's URL semantics. The specified URL must also be compatible with the Exchange store. For information about building compatible URLs, see Exchange Store URLs.

The enumerated values and their semantic definitions are defined as part of the ActiveX Data Objects database (ADODB) type library and documentation. Consult the ADO (ADO) 2.5 documentation for a list of valid enumeration values and their intended purposes. Use of various enumerated values and their intended meanings is specific to a particular OLE DB 2.5 provider.

Restrictions on what types of data can be saved into a particular resource and how that data is handled by an implementation of the IDataSource interface is not part of this definition. Consult the appropriate Component Object Model (COM) class reference for further information.


        [Visual Basic]

' Reference to Microsoft CDO for Exchange 2000 Library
' Reference to Microsoft ActiveX Data Objects 2.5 Library

' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
Function CreateAndSaveMessageTo(Url1 As String) As CDO.message

    Dim iDsrc As CDO.IDataSource
    Dim Conn As New ADODB.Connection
    Conn.Provider = "ExOLEDB.DataSource"
    Conn.Open Url1

    Dim iMsg As New CDO.message

    With iMsg
        .To       = ""
        .From     = ""
        .Subject  = "Here is the subject"
        .TextBody = "Here is the text of the message"
    End With

    Set iDsrc = iMsg

    iDsrc.SaveTo Url1 & "/mymessage.eml", _
                Conn, _

    ' Close connection
    Set Conn = Nothing

    Set CreateAndSaveMessageTo = iMsg

End Function


 // You must have the following paths in your
 // INCLUDE path.
 // %CommonProgramFiles%\system\ado
 // %CommonProgramFiles%\microsoft shared\cdo

#import <msado15.dll> no_namespace
#import <cdoex.dll> no_namespace
#include <iostream.h>
#define BUFLEN   40

// Note: It is recommended that all input parameters be validated when they are
// first obtained from the user or user interface.
void SaveMessageToFolder1(IMessagePtr pMsg, bstr_t url) {

   _ConnectionPtr pConn(__uuidof(Connection));

   if(pMsg == NULL)
      throw _com_error(E_INVALIDARG);

   // For passing optional variants, you may need the following.
   _variant_t varOpt(DISP_E_PARAMNOTFOUND,VT_ERROR);
   IDataSourcePtr pDsrc = pMsg;

   pConn->Provider = "ExOLEDB.DataSource";
   try {
   catch(_com_error e) {
      throw e;
   GUID g;
   if(FAILED(CoCreateGuid(&g))) {
      cerr << "Error creating GUID" << endl;
      throw _com_error(E_FAIL);
   wchar_t buf[BUFLEN];
   if( StringFromGUID2(g,(wchar_t*)buf,BUFLEN) == 0 ) {
      cerr << "Error getting string from GUID?" << endl;
      throw _com_error(E_UNEXPECTED);

   try {
            url + bstr_t(buf) + bstr_t(".eml"),

            // Connection from Folder bind above.
            (RecordOpenOptionsEnum) NULL,
   catch(_com_error e) {
      cerr << "Error saving message to folder!" << endl;
      throw e;

   // Close connection.
   pConn = NULL;

<job id="idatasource_saveto">
<reference object="adodb.record"/>
<reference object="cdo.message"/>
<script language="vbscript">

    Dim iDsrc
    Dim iMsg
    Dim Conn
    Dim InfoNT
    Dim Info
    Dim sFolderUrl

    Set Info   = CreateObject("ADSystemInfo")
    Set InfoNT = CreateObject("WinNTSystemInfo")
    Set Conn   = CreateObject("ADODB.Connection")
    Set iMsg   = CreateObject("CDO.Message")

    sFolderUrl = "http://" & InfoNt.ComputerName & "." & Info.DomainDNSName &  _

    Conn.Provider = "ExOLEDB.DataSource"
    Conn.Open sFolderUrl

    ' ...

    With iMsg
        .To   = ""
        .From = ""
        .Subject = "Here is the subject"
        .TextBody = "Here is the text of the message"
    End With

    Set iDsrc = iMsg.DataSource
    iDsrc.SaveTo sFolderUrl & "/item10.eml", Conn
    Wscript.Echo "Saved To and bound to item at URL: " & iDsrc.SourceURL

    iMsg.TextBody = iMsg.TextBody & vbCrLf & "And this is another line."

    ' Close connection
    Set Conn = Nothing