This documentation is archived and is not being maintained.

Open Method

Exchange Server 2003

Open 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 opens data from the existing item specified by the URL.

Applies To

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In



        [Visual Basic]Sub Open
    SourceURL As String,     [ActiveConnection As Object],     [Mode As ConnectModeEnum],     [CreateOptions As RecordCreateOptionsEnum],     [Options As RecordOpenOptionsEnum],     [UserName As String],     [Password As String]

        [C++]HRESULT Open
    BSTR SourceURL,
    ConnectModeEnum Mode,
    RecordCreateOptionsEnum CreateOptions,
    RecordOpenOptionsEnum Options,
    BSTR UserName,
    BSTR Password


Specifies the URL of the existing item to open. New items cannot be created using the Open method. Use SaveTo or SaveToContainer.
Specifies the connection to use when opening. This is a reference to a Microsoft ActiveX Data Objects (ADO) Connection object. A new Connection object (session) is created implicitly if none is specified.
ADO-defined access mode enumeration. The specified value is always ORed with adModeRead (1). This means that at least read access is requested when opening an item, not that only read access is requested.
Must be adFailIfNotExists. New items cannot be created using the Open method.
This specifies the options flag opening the source. The only supported open option is adOpenAsynch. 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. Once 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 Open method has an identical signature to the Open method defined by ADO interfaces such as the _Record, _Recordset, and _Stream interfaces. The IDataSource.Open method, unlike the _Record.Open or _Stream.Open, cannot be used to create new items. Therefore, the CreateOption parameter must always be set to adFailIfNotExists. The other enumerated values and their semantic definitions are defined as part of the ADO type library and documentation. Consult the ADO 2.5 documentation for a list of valid enumeration values and their intended purpose. Use of various enumerated values and their intended meaning is specific to a particular OLE DB 2.5 provider.

Restrictions on what types of data can be opened 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.

Note  This Microsoft Visual Basic example uses a file URL with the Exchange OLE DB (ExOLEDB) provider. The ExOLEDB provider also supports The HTTP: URL Scheme.


        [Visual Basic]

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

    Dim iFldr As New Folder
    Dim iDsrc As CDO.IDataSource
    Dim Conn As New ADODB.Connection
    Dim Url1 As String

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

    Set iDsrc = iFldr

    Url1 = "file://./backofficestorage/"

    ' Open base mailbox folder:
    iDsrc.Open Url1, Conn, adModeReadWrite

    Dim iMsg As New CDO.message
    Set iDsrc = iMsg

    iDsrc.Open Url1 & "/Drafts/item8.eml", _
                Conn, _

    ' Close connection
    Set Conn = Nothing


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

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

IItemPtr OpenItem() {

    bstr_t url = "file://./backofficestorage/";
   _bstr_t bstrEmpty("");

   IDataSourcePtr pDsrc(__uuidof(Item));
   _variant_t varOpt(DISP_E_PARAMNOTFOUND,VT_ERROR);

   _ConnectionPtr pConn(__uuidof(Connection));

   pConn->Provider = "ExOLEDB.DataSource";

   try {
      pConn->Open(url, bstr_t(),bstr_t(),-1);
   catch(_com_error e) {
      throw e;

   try {
         variant_t( (IDispatch*)pConn, true),
   catch(_com_error e) {
      cerr << "Error opening item" << endl;
      throw e;

   // Close connection.
   pConn = NULL;

   return pDsrc;

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

    Dim iMbx
    Dim iPer
    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")
    Set iPer   = CreateObject("CDO.Person")

    iPer.DataSource.Open "LDAP://" & Info.UserName
    Set iMbx = iPer.GetInterface("IMailbox")

    Conn.Provider = "ExOLEDB.DataSource"
    Conn.Open iMbx.baseFolder

    ' ...

    Set iDsrc = iMsg.DataSource

    iDsrc.Open iMbx.Inbox & "/subject.eml", _
                Conn, _

    wscript.echo iMsg.From
    wscript.echo iMsg.Subject

    ' Close connection.
    Set Conn = Nothing
    ' ...