- The ADO/OLE DB Conspiracy
- What Does ADO 2.5 Have to Do with Exchange 2000?
- The Role of the Web Storage System
- The Exchange OLE DB Provider
- File URLs
- HTTP URLs
- Programmatically Getting a User's HTTP Mailbox Folder URLs
- The Open Method of the ADO 2.5 Record Object
- Using Web Storage System SQL to Get a List of Folders
- Web Storage System SQL
- The SELECT Statement
- The ORDER BY Clause
- The RANK BY Clause
- Some Unsupported SQL
- Summary
The Open Method of the ADO 2.5 Record Object
Let's return to our initial example of creating a folder using the Open method of the Record object from earlier in the chapter:
objRec.Open sURL, objConn, adModeReadWrite, adCreateCollection
The Open method is used to bind to and open data from an item specified by a valid URL. The signature for the Open method is as follows:
Open (ByVal SourceURL as String, [ByVal ActiveConnection as Object], [ByVal Mode as ConnectModeEnum], [ByVal CreateOptions as RecordCreateOptionsEnum], [ByVal Options as RecordOpenOptionsEnum], [ByVal UserName as String], [ByVal Password as String])
where
-
SourceURL specifies the URL of the existing item to open.
-
ActiveConnection (optional) is a reference to an ADO Connection object specifying the connection to use when opening the URL. A new Connection object (session) is implicitly created if none is specified.
-
Mode (optional) is a reference to the ADO-defined ConnectModeEnum. The default value is always adModeRead (1), which means that at least read access is requested when an item is opened. You can add the values as appropriate for your application needs. The possible values are shown in Table 7.5.
-
CreateOptions (optional) is a reference to the ADO-defined RecordCreateOptionsEnum. For our purposes, adCreateCollection creates a folder item (a collection of other items), and adCreateNonCollection creates a file (noncollection). The possible values are shown in Table 7.6.
Table 7.5 ConnectModeEnum Values
Name | Value |
---|---|
adModeRead | 1 |
adModeReadWrite | 3 |
adModeRecursive | 4194304 (&H$00000) |
adModeShareDenyNone | 16 (&H10) |
adModeShareDenyRead | 4 |
adModeShareDenyWrite | 8 |
adShareExclusive | 12 (&H0C) |
adModeUnknown | 0 |
adModeWrite | 2 |
Table 7.6 RecordCreateOptionsEnum Values
Name | Value |
---|---|
adCreateCollection | 8192 (&H2000) |
adCreateNonCollection | 0 |
adCreateOverwrite | 67108864 (&H4000000) |
adCreateStructDoc | -2147483648 (&H80000000) |
adFailIfNotExists | -1 (&HFFFFFFFF) |
adOpenIfExists | 33554432 (&H2000000) |
-
Options (optional) is a reference to the ADO-defined RecordOpenOptionsEnum. The possible values are shown in Table 7.7.
-
UserName (optional) is normally used to pass a user name if needed for authentication; however, this value is not supported in the ExOLEDB provider
-
Password (optional) is normally used to pass a password if needed for authentication; however, this value is not supported in the ExOLEDB provider.
Table 7.7 RecordOpenOptionsEnum Values
Name | Value |
---|---|
adDelayFetchFields | 32768 (&H8000) |
adDelayFetchStream | 16384 (&H4000) |
adOpenSync | 4096 (&H1000) |
adOpenRecordUnspecified | -1 (&HFFFFFFFF) |
adOpenSource | 8388608 (&H800000) |
The Open method is crucial because it allows us to bind to any existing item in the Web Storage System or even create new ones. For example, the following code creates a simple CDO item at the requested URL (assuming that sURL holds a valid URL and objConn represents a valid connection to the Exchange server):
Dim objRec As New ADODB.Recordset objRec.Open sURL, objConn, adModeReadWrite, adCreateNonCollection objRec.Fields("DAV:contentclass") = "urn:content-classes:item" objRec.Fields("urn:schemas:mailheader:content-type") = "text/plain" objRec.Fields.Update
The same code with a minor change will try to bind to an existing item:
Dim objRec As New ADODB.Recordset objRec.Open sURL, objConn, adModeReadWrite
Rather than indiscriminately getting one item, we can combine the Open statement with a form of SQL to query folders for a "result set" that can be returned as a standard ADO Recordset.