- 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
Programmatically Getting a User's HTTP Mailbox Folder URLs
Returning to our sample VB project, go to the Project menu in the VB integrated development environment and click Components . In the Controls tab select Microsoft Forms 2.0 Object Library. Drop a Forms 2.0 list box on frmMain and call it lstMailboxURLs. This is the gray list box shown in Figure 7.5. This is part of the standard Microsoft Office installation. If you don't have Office on your computer, then you can use a regular VB list box and modify the sample code accordingly. It just seems easier to work with this list box in demo code. Create a button on frmMain and call it cmdGetMailboxURLs.
In the click event of your cmdGetMailboxURLs button, insert the following code:
Private Sub cmdGetMailboxURLs_Click() Dim vaURLs As Variant Dim nCounter As Integer Dim sText As String ' These 2 objects allow us to dynamically figure out the computer name and ' the domain name, respectively, as in the call to ' GetStdWellKnownMailboxURLs: Dim objInfo As New ActiveDS.ADSystemInfo Dim objInfoNT As ActiveDS.WinNTSystemInfo ' The URL should be something like: ' http://gomezawin2000.gomezamobile.local/exchange/Administrator vaURLs = GetStdWellKnownMailboxURLs("http://" & _ LCase(objInfoNT.ComputerName) & "." & _ objInfo.domaindnsname & "/exchange/" & objInfoNT.UserName) ' Display it: frmMain.lstMailboxURLs.Clear For nCounter = LBound(vaURLs) To UBound(vaURLs) frmMain.lstMailboxURLs.AddItem vaURLs(nCounter) Next Set objInfo = Nothing Set objInfoNT = Nothing End Sub
When using functions such as the ones we have seen in the sample code, we often need to pass a fully qualified URL. When writing production applications, it is rarely feasible to hard-code such things as server names and domains. Using the following technique, we can dynamically determine the local machine name and domain. We can do this thanks to two standard ADSI interfaces for Windows 2000 that you get automatically on any Windows 2000 system. The ADSystemInfo and WinNTSystemInfo objects give us all sorts of useful information about our environment (like the name of our computer). All we have to do is declare them. We use them to build our "http://" URL to the Administrator's mailbox, which we pass to GetStdWellKnownMailboxURLs.
Note: To use ADSystemInfo and WinNTSystemInfo in your VB project, set a reference to the "Active DS Type Library" (found in C:\WINNT\System32\activeds.tlb ). To use them in VBScript code, use CreateObject like so:
Set objInfo = CreateObject("ADSystemInfo") Set objInfoNT = CreateObject("WinNTSystemInfo")
For more information, see the ADSI Platform SDK on the Microsoft Developer Network (http://msdn.microsoft.com/library/default.asp).
The preceding discussion showed how to reference default mailbox folder files. Now we will write some code to programmatically get all default mailbox folder URLs for a given user. This approach avoids having to hard-code the paths in your application. We will once again use our Administrator user's mailbox. The following VB function will return an array of the default mailbox URLs for a given mailbox:
Public Function GetStdWellKnownMailboxURLs(sMailboxFolderURL As String) As Variant Dim objRec As ADODB.Record Dim objConn As ADODB.Connection Dim objFields As ADODB.Fields Set objRec = New ADODB.Record Set objConn = New ADODB.Connection ' Connect to the local Exchange server: ' We previously declared: _ ' Global Const gblsExchangeProvider = "ExOLEDB.DataSource" objConn.Provider = gblsExchangeProvider objConn.Open sMailboxFolderURL objRec.Open sMailboxFolderURL Set objFields = objRec.Fields ' Return the Mailbox URLs as an array: GetStdWellKnownMailboxURLs = Array( _ "Calendar: ", objFields(cdoCalendarFolderURL), _ "Contacts: ", objFields(cdoContactFolderURL), _ "DeletedIt:", objFields(cdoDeletedItems), _ "Inbox: ", objFields(cdoInbox), _ "Journal: ", objFields(cdoJournal), _ "MsgRoot: ", objFields(cdoMsgFolderRoot), _ "Notes: ", objFields(cdoNotes), _ "Outbox: ", objFields(cdoOutbox), _ "SendMsg: ", objFields(cdoSendMsg), _ "SendItems: ", objFields(cdoSentItems), _ "Tasks: ", objFields(cdoTasks)) ' Clean up: objRec.Close objConn.Close Set objRec = Nothing Set objConn = Nothing End Function
This code returns a variant array (which we display in our form by doing simple AddItem calls) containing the following strings:
http://gomezawin2000.GomezaMobile.local/exchange/Administrator/Calendar http://gomezawin2000.GomezaMobile.local/exchange/Administrator/Contacts http://gomezawin2000.GomezaMobile.local/exchange/Administrator/Deleted%20Items http://gomezawin2000.GomezaMobile.local/exchange/Administrator/Inbox http://gomezawin2000.GomezaMobile.local/exchange/Administrator/Journal http://gomezawin2000.GomezaMobile.local/exchange/Administrator http://gomezawin2000.GomezaMobile.local/exchange/Administrator/Notes http://gomezawin2000.GomezaMobile.local/exchange/Administrator/Outbox http://gomezawin2000.GomezaMobile.local/exchange/Administrator/ _ %23%23DavMailSubmissionURI%23%23 http://gomezawin2000.GomezaMobile.local/exchange/Administrator/Sent%20Items http://gomezawin2000.GomezaMobile.local/exchange/Administrator/Tasks
The CDO HTTP mail constants we used in the code for this example (e.g., cdoCalendarFolderURL, cdoContactFolderURL, cdoDeletedItems) were defined courtesy of the Microsoft CDO for Exchange 2000 library to which we set a reference earlier. We will look specifically at CDO for Exchange 2000 in other chapters; Table 7.4 summarizes the value of these constants (in case you need to use this code in VBScript, for example).
Table 7.4 Mailbox Folder URL Constraints
|cdoHTTPMail Constraint||Value||Mailbox Folder Name|
|cdoSendMsg||urn:schemas:httpmail:sendmsg||Exchange Mail Submission URI|
|cdoMsgFolderRoot||urn:schemas:httpmail:msgfolderroot||Mailbox root URL|
As we shall see in much greater detail later in the book, the connection between ADO and CDO comes down to this: We use ADO to get the data and CDO to interpret it.