Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27390

VS 2008 Using VB to query Exchange

$
0
0
I have found sample code for using VB to query out appointment information from MS Exchange. I am not able to get the code to compile and could use some insight from anyone that may have tried this before.

Using Visual Studio 8 Professional on a Windows 7 64 bit.

The code is failing on three lines of code:
Dim iAppt As New CDO.Appointment
Dim info As New ADSystemInfo
ItemURL = Rs.Fields(CdoDAV.cdoHref).Value

All fail with type is not defined. Figured it is a reference issue so I tried tackling CDO first. My reference library only shows Microsoft CDO for Windows 2000 Library. I added it but still doesn't work. Did some research and found there is a Microsoft CDO for Exchange 2000 library. Found the install from Microsoft. Uninstalled Outlook from my machine and installed this (had to uninstall because package would not install on machine with outlook). In my references, I now see Microsoft CDO 1.21 library but no Exchange 2000 Library. It is using the correct CDO.dll so I added it to the project. Still no joy.

Wondering what I am missing.

Below I will show the complete code in case anyone needs to see it. Basically, I need to query out all calendar events for a single user in exchange and store in a SQL database. This code seemed straight forward for pulling the records and all I had to do was write new code to store into SQL. If I am going in the wrong direction, I am open for suggestions.

Thx,
Douglas

Code:
Code:

   
Private Sub FilterAppointments(ByVal User1)
        Dim CalendarURL As String
        Dim ItemURL As String
        Dim Rs As New ADODB.Recordset
        Dim Rec As New ADODB.Record
        Dim iAppt As New CDO.Appointment
        Dim iAttendees As Object
        Dim DebugStr As String
        Dim DomainName As String
        Dim info As New ADSystemInfo

        ' Get the domain name.
        DomainName = info.DomainDNSName

        ' Construct the URL that will be used to reach the specified Calendar folder.
        ' Note: You can view a calendar folder belonging to someone else (or a public folder),
        ' as long as the mailbox of that user (or the public folder) resides in the local
        ' computer and you have sufficient permissions to view it.

        ' If the Calendar folder is a public folder, the CalendarURL string will look like the following:
        ' CalendarURL = "file://./backofficestorage/" & DomainName & "/public folders/" & "NameOfTheCalendarFolder"

        CalendarURL = "file://./backofficestorage/" & DomainName & "/MBX/" & User1 & "/calendar/"

        'Open a recordset for the items in the calendar folder.
        Rec.Open(CalendarURL)

        Rs.ActiveConnection = Rec.ActiveConnection
        Rs.Source = "SELECT ""DAV:href"", " & _
        " ""urn:schemas:calendar:busystatus"", " & _
        " ""urn:schemas:calendar:instancetype"", " & _
        " ""urn:schemas:calendar:dtstart"", " & _
        " ""urn:schemas:calendar:dtend"" " & _
        "FROM scope('shallow traversal of """ & CalendarURL & """') " & _
        "WHERE (""urn:schemas:calendar:dtstart"" >= CAST(""1999-12-25T08:00:00Z"" as 'dateTime')) " & _
        "AND (""urn:schemas:calendar:dtend"" <= CAST(""1999-12-29T08:00:00Z"" as 'dateTime'))" & _
        "AND (""urn:schemas:calendar:busystatus"" = 'Busy')" & _
        "AND (""urn:schemas:calendar:instancetype"" = 0)"
        Rs.Open()
        If Not (Rs.EOF) Then
            Rs.MoveFirst()
            DebugStr = ""

            ' Enumerate the recordset, printing some information about each item.
            Do Until Rs.EOF

                ' Find the absolute uniform resource locator (URL) of each item.
                ItemURL = Rs.Fields(CdoDAV.cdoHref).Value

                ' Open the appointment using its URL.
                iAppt.DataSource.Open(ItemURL)

                DebugStr = DebugStr & "Subject: " & iAppt.Subject & vbLf
                DebugStr = DebugStr & "Start-End Time: " & iAppt.StartTime & " - " & iAppt.EndTime & vbLf
                DebugStr = DebugStr & "Location: " & iAppt.Location & vbLf
                DebugStr = DebugStr & "Attendees: "

                ' Find the attendees who are invited to each meeting.
                iAttendees = iAppt.Attendees
                For i = 1 To iAttendees.Count
                    DebugStr = DebugStr & iAttendees(i).DisplayName & " "
                Next
                DebugStr = DebugStr & vbLf & vbLf
                Rs.MoveNext()
            Loop
            Debug.Print(DebugStr)

            ' No appointments were found that match the search criteria.
        Else
            Debug.Print("No Appointments found.")
        End If
    End Sub


Viewing all articles
Browse latest Browse all 27390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>