SaveTo Method

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

IDataSource Interface

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In

CDOEX.DLL

Syntax

[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,     IDispatchActiveConnection,     ConnectModeEnum Mode,     RecordOpenOptionsEnum CreateOptions,     RecordOpenOptionsEnum Options,     BSTR Username,     BSTR Password,     BSTR UserName );

Parameters

  • SourceURL
    The URL specifying where to save.

  • ActiveConnection
    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.

  • Mode
    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.

  • CreateOptions
    Creation options for the new item. The values adFailIfNotExists and adOpenIfExists should not be used. If used, an E_INVALIDARG exception is raised.

  • Options
    This specifies options flag(s) opening the source. Your setting is always ORed with adOpenSource.

  • Username
    Used to pass a user name if needed for authentication.

  • Password
    Used to pass a password if needed for authentication.

  • UserName

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

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.

Examples

[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       = "someone@example.com"
    .From     = "another@example.com"
    .Subject  = "Here is the subject"
    .TextBody = "Here is the text of the message"
End With

Set iDsrc = iMsg

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

' Close connection
Conn.Close
Set Conn = Nothing

Set CreateAndSaveMessageTo = iMsg

End Function

[C++]

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

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

// 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 { pConn->Open(url,bstr_t(),bstr_t(),-1); } 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]; memset((void*)(wchar_t*)buf,0,BUFLEN); if( StringFromGUID2(g,(wchar_t*)buf,BUFLEN) == 0 ) { cerr << "Error getting string from GUID?" << endl; throw _com_error(E_UNEXPECTED); }

try { pDsrc->SaveTo( url + bstr_t(buf) + bstr_t(".eml"),

        // Connection from Folder bind above.
        variant_t((IDispatch*)pConn,true),
        adModeReadWrite,
        adCreateNonCollection,
        (RecordOpenOptionsEnum) NULL,
        bstr_t(),
        bstr_t()
        );

} catch(_com_error e) { cerr << "Error saving message to folder!" << endl; throw e; }

// Close connection. pConn->Close(); 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://" &amp; InfoNt.ComputerName &amp; "." &amp; Info.DomainDNSName &amp;  _
       "/public/test_folder/"

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

' ...

With iMsg
    .To   = "someone@example.com"
    .From = "another@example.com"
    .Subject = "Here is the subject"
    .TextBody = "Here is the text of the message"
End With

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

iMsg.TextBody = iMsg.TextBody &amp; vbCrLf &amp; "And this is another line."
iDsrc.Save

' Close connection
Conn.Close
Set Conn = Nothing

</script> </job>

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.