다음을 통해 공유


Open Method

Topic Last Modified: 2006-06-13

Binds to and opens data from the existing item specified by the URL.

Applies To

IDataSource Interface

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In

CDOEX.DLL

Syntax

Sub Open(    SourceURL As String,
    [ActiveConnection As Object],
    [Mode As ConnectModeEnum],
    [CreateOptions As RecordCreateOptionsEnum],
    [Options As RecordOpenOptionsEnum],
    [UserName As String],
    [Password As String])
HRESULT Open
(
        BSTR SourceURL,
        IDispatch* ActiveConnection,
        ConnectModeEnum Mode,
        RecordCreateOptionsEnum CreateOptions,
        RecordOpenOptionsEnum Options,
        BSTR UserName,
        BSTR Password
);

Parameters

  • SourceURL
    Specifies the URL of the existing item to open. New items cannot be created using the Open method. Use SaveTo or SaveToContainer.
  • ActiveConnection
    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.
  • Mode
    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.
  • CreateOptions
    Must be adFailIfNotExists. New items cannot be created using the Open method.
  • Options
    This specifies the options flag opening the source. The only supported open option is adOpenAsynch. 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.

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

Examples


' 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/example.com/MBX/useralias/"

    ' 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, _
                adModeReadWrite

    ' Close connection
    Conn.Close
    Set Conn = Nothing



/*
 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>
#endif

IItemPtr OpenItem() {

    bstr_t url = "file://./backofficestorage/example.com/MBX/useralias/";
   _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 {
      pDsrc->Open(
         url,
         variant_t( (IDispatch*)pConn, true),
         adModeRead,
         adFailIfNotExists,
         adOpenSource,
         bstr_t(),
         bstr_t()
         );
   }
   catch(_com_error e) {
      cerr << "Error opening item" << endl;
      throw e;
   }

   // Close connection.
   pConn->Close();
   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, _
                adModeReadWrite

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

    ' Close connection.
    Conn.Close
    Set Conn = Nothing
    ' ...
</script>
</job>