On Tue, 14 May 2002 03:40:48 -0500, Fernando, Chaminda non Unisys
<[EMAIL PROTECTED]> wrote:

>Hi all,
>        I want to get holidays in an year in a particular country. How can
I
>do that ? In Outlook Calendar I can see holidays when I set to particular
>country (Default US). So how can I access it from vb.net ?
>regards,
>mcdf
>
>You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.

The following VB.NET code fragment prints all the holidays registered in
the default Outlook Calendar folder for a specific country and year in date
sequence. The values in the restrict string probably need to be adjusted to
reflect the specific local language setting for the client.
You can check the LanguageSettings property of the Outlook Application
object to determine this. It was tested on Outlook 2002 but should also
work on other versions.

- Mike

-------------------

Imports Outlook = Microsoft.Office.Interop.Outlook

Module Module1

    Sub Main()

        Dim olApp As Outlook.Application
        Dim olNS As Outlook.NameSpace
        Dim olCalendar As Outlook.MAPIFolder
        Dim olItems As Outlook.Items
        Dim olHolidays As Outlook.Items
        Dim olHoliday As Outlook.AppointmentItem

        Const CANADIAN_HOLIDAYS_2002 As String = _
        "[Categories] = 'Holiday' And [Location] = 'Canada' And [Start]
> '31/12/2001' And [End] < '1/1/2003'"

        'piggyback on existing Outlook session
        olApp = New Outlook.Application()
        olNS = olApp.GetNamespace("MAPI")
        olNS.Logon(, , False, False)

        olCalendar = olNS.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderCalendar)
        olHolidays = olCalendar.Items.Restrict(CANADIAN_HOLIDAYS_2002)
        olHolidays.Sort("[Start]")

        ' Note can't use For Each because of bug in generated Outlook
interop.
        Dim i As Integer
        For i = 1 To olHolidays.Count
            olHoliday = olHolidays.Item(i)
            Debug.WriteLine(olHoliday.Start.ToString & " " &
olHoliday.Subject)
        Next

    End Sub

End Module

Output
------

01/01/2002 12:00:00 AM New Year's Day
14/02/2002 12:00:00 AM Valentine's Day
18/02/2002 12:00:00 AM Family Day - Provincial Alberta
17/03/2002 12:00:00 AM Saint Patrick's Day
29/03/2002 12:00:00 AM Good Friday
31/03/2002 12:00:00 AM Easter
01/04/2002 12:00:00 AM Easter Monday
12/05/2002 12:00:00 AM Mother's Day
20/05/2002 12:00:00 AM Victoria Day
.......
(Note: We don't get all these off <g>)

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to