다음을 통해 공유


DataSource Property (IFolder)

Topic Last Modified: 2006-06-13

The IDataSource interface on the object. This property is read-only.

Applies To

IFolder Interface

Type Library

Microsoft CDO for Exchange 2000 Library

DLL Implemented In

CDOEX.DLL

Syntax

Property DataSource As IDataSource
HRESULT get_DataSource(IDataSource** pVal);

Parameters

Remarks

This property returns the IDataSource interface on the object. Use the IDataSource interface exposed by the object to bind to items in an Exchange store or to other objects, such as Microsoft® ActiveX® Data Objects (ADO) Record or OLE DB Row objects. When binding to Record and Row objects, the underlying store item must be a container.

Examples


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

' Note: It is recommended that all input parameters be validated before being used.
Function GetBoundFolder(Url As String) As CDO.Folder
  Set Fldr = New Folder
  Set GetBoundFolder = Fldr.DataSource.Open(Url, , _
                                            adModeReadWrite, _
                                            adFailIfNotExists)

End Function

' Note: It is recommended that all input parameters be validated before being used.
Function GetBoundFolder( Url )
  Set Fldr = CreateObject("CDO.Folder")
  Set GetBoundFolder = Fldr.DataSource.Open(Url, , _
                                            adModeReadWrite, _
                                            adFailIfNotExists)

End Function



/*
 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
// Note: It is recommended that all input parameters be validated before being used.
IFolderPtr CreateFolder(bstr_t url, bstr_t contentclass, bstr_t description) {

   if(url == bstr_t(""))
      throw _com_error(E_POINTER);

   _ConnectionPtr Conn(__uuidof(Connection));
   IDataSourcePtr pDsrc(__uuidof(Folder));

   Conn->Provider = "ExOLEDB.DataSource";
   try {
      Conn->Open(url,bstr_t(),bstr_t(),-1);
   }
   catch(_com_error e) {
      throw e;
   }

   IFolderPtr pFldr = pDsrc;

   pFldr->ContentClass = contentclass;
   pFldr->Description  = description;

   try {
      pDsrc->SaveTo(
         url,
         variant_t((IDispatch*)Conn,true),
         adModeReadWrite,
         (RecordCreateOptionsEnum)
            (   adCreateCollection |
               adCreateOverwrite
            ),
         adOpenSource,
         bstr_t(),
         bstr_t());
   }
   catch(_com_error e) {
      cerr << "Error saving folder to store" << endl;
      throw e;
   }

   // close connection
   Conn->Close();
   Conn = NULL;

   return pFldr;
}