views:

451

answers:

1

We have to add and update outlook calendar events for several users (different appointments events for each user) under program control (VB or Ruby). A server solution with no action required by individual users is preferred. Simple ICAL based technology doesn't appear to easily support updating existing events (i.e. schedule changes).

Any pointers (Snippets, API docs would be appreciated)

BTW: A Non-server based solution where each user has to run a script similar to following is what we currently have:

# Loosely based on http://snippets.dzone.com/posts/show/4301

require 'delegate_to'
require 'win32ole'

# Simple DSL wrapper out Outlook API
class OutlookCalendar < Array
    CALENDAR_FOLDER=9
    OUTLOOK=WIN32OLE.new 'Outlook.Application'

    class Event
        def initialize &block
            @_=OutlookCalendar::OUTLOOK.CreateItem 1
            instance_eval(&block) if block_given?
        end
        def subject *arg
            @_.subject=arg.first unless arg.empty?
            @_.Subject
        end
        def start *arg
            @_.Start=arg.first unless arg.empty?
            @_.Start
        end
        def duration *arg
            @_.Duration=arg.first unless arg.empty?
            @_.Duration
        end
        def body *arg
            @_.Body=arg.first unless arg.empty?
            @_.Body
        end
        def location *arg
            @_.Location=arg.first unless arg.empty?
            @_.location
        end
        def reminder *arg
            @_.ReminderMinutesBeforeStart=arg.first unless arg.empty?
            @_.ReminderSet=true
            @_.ReminderMinutesBeforeStart
        end

        delegate_to :_
    end


    def initialize
        super
        refresh
        each{|_| yield _} if block_given?
    end

    def refresh
        mapi=OutlookCalendar::OUTLOOK.GetNameSpace 'MAPI'
        @calendar=mapi.GetDefaultFolder CALENDAR_FOLDER
        entries=[] #  [ Subject Location Start End Body ]
        @calendar.Items.each{|_| entries << _} # can't use collect
        self.replace entries.sort_by{|_| _.Start}
        self
    end

    def << event
        event.save
    end
end

# Sample Usage:
if $0==__FILE__

    class OutlookCalendar
        def show
            each{|_| puts '%s - %s : %s' % [ _.Start,_.End,_.Subject ]}
        end
    end

    Calendar=OutlookCalendar.new

    # Show original events
    Calendar.show

    # Delete possible previous events       
    Calendar.each{|_| _.Delete if /^S3W:/.match _.Subject}

    # Add updated event
    Calendar << OutlookCalendar::Event.new do
        start '7/29/2007 11:00 AM'
        duration 300
        subject 'S3W: Hall of Fame Induction'
        body 'Tony Gwynn and Cal Ripken Jr.'
        location 'Cooperstown, NY'
        reminder 15
    end

    # Show updated list of events
    puts '-'*50
    Calendar.refresh.show

end
A: 

Outlook, Exchange, and WebDav.

  • How to create an Outlook Calendar folder by using WebDAV in Visual C#
  • How to work with items in Exchange 2000 by using WebDAV in Visual Basic .NET
AMissico
Thanks... The second item was helpful. The problem with a WebDav approach is the authentication... Username/Password maintenance for each user is a problem. Is some other API/approach possible so that a trusted server Admin can pop events into specific user's Outlook calendar?
DMisener
Yes. We use ActiveDirectory (LDAP), but some of my proof-of-concept used a development administrator. I am sorry, I just deleted the source code a few weeks ago because I no longer work at the company.
AMissico