다음을 통해 공유


Enumerating Event Registrations for a Folder

Topic Last Modified: 2006-06-11

The following code opens an event registration item and lists the events it is registering.

Example

Visual Basic

Public Sub Enum_Event(Server As String)
  On Error Resume Next
  Dim Query
  Dim fld

  Dim rs As New ADODB.Recordset
  Dim strParentFolder
  Dim strEventRegistrationName
  Dim aPropNames

  aPropNames = Array( _
    "DAV:contentclass", _
    "https://schemas.microsoft.com/exchange/events/Criteria", _
    "https://schemas.microsoft.com/exchange/events/Enabled", _
    "https://schemas.microsoft.com/exchange/events/EventMethod", _
    "https://schemas.microsoft.com/exchange/events/MatchScope", _
    "https://schemas.microsoft.com/exchange/events/Priority", _
    "https://schemas.microsoft.com/exchange/events/ScriptUrl", _
    "https://schemas.microsoft.com/exchange/events/SinkClass", _
    "https://schemas.microsoft.com/exchange/events/TimerExpiryTime", _
    "https://schemas.microsoft.com/exchange/events/TimerInterval", _
    "https://schemas.microsoft.com/exchange/events/TimerStartTime")


  ' Specify the event folder and the event registration name
  strParentFolder = "file://./backofficestorage/" + _
                     Server + "/mbx/user1/inbox"

  strEventRegistrationName = "evtreg1"  'If you want to enum all the events, then leave this blank

  'Build the sql query to get the events
  'This section gets all event types so that you don't have to change this per event type
  'To limit the event types, remove the unwanted event types from aPropNames
  Dim i

  Query = "SELECT "
  For i = LBound(aPropNames) To UBound(aPropNames)
    Query = Query + Chr(34) + aPropNames(i) + Chr(34)
    If i <> UBound(aPropNames) Then
      Query = Query + ", "
    End If
  Query = Query + " FROM SCOPE('shallow traversal of " + Chr(34) + strParentFolder + Chr(34) + "')"
  Query = Query + " WHERE " + Chr(34) + "DAV:contentclass" + Chr(34) + " = 'urn:content-class:storeeventreg'"
  If strEventRegistrationName <> "" Then
    'event folder name specified
    Query = Query + " AND " + Chr(34) + "DAV:displayname" + Chr(34) + " = '" + strEventRegistrationName + "'"
  End If


  Dim rec As New ADODB.Record
  rec.Open strParentFolder  'root binder will select the correct provider
  If Err.Number <> 0 Then
    Debug.Print "Error Executing Query : " & Err.Number & " " & Err.Description & vbCrLf
    Exit Sub
  End If

  rs.Open Query, rec.ActiveConnection
  If Err.Number <> 0 Then
    Debug.Print "Error Executing Query : " & Err.Number & " " & Err.Description & vbCrLf
    Exit Sub
  End If

  ' Go thru each entry in the recordset
  Do While (rs.BOF <> True And rs.EOF <> True)
    For Each fld In rs.Fields
      If fld.Value <> vbNull Then
        Debug.Print fld.Name & ", " & fld.Value & vbCrLf
      End If
    Debug.Print "***********************************************" & vbCrLf
    rs.MoveNext
    If Err.Number <> 0 Then
      Debug.Print "Error Moving To Next Record : " & Err.Number & " " & Err.Description & vbCrLf
      Exit Sub
    End If
  Loop

  Set rs = Nothing

End Sub