0
votes

Is there a way to synchronize Outlook local shared calendars with their Exchange vesion programatically?

I tried Namespace.SendAndReceive() but it seems it doesn't affect calendars...

Is there something I miss or is it just impossible ?

I would like to perform a "send" from my local shared calendar folder to his server folder.

(I know it is possible to work directly on the server version by unchecking "Download shared calendar" as showed here but I can't do this way)

EDIT : Why do I try to force sync?

In my add-in, users create new appointments in a shared calendar, and then lauch a function that makes a HTTP request to a script working with EWS to get this exchange calendar. But as the new appointments aren't sent, the script communicating with EWS don't get new appointments.

I found out the "update folder" button in Send/Receive sends the folder to exchange server but looking at the folder object I don't find how to do it programatically...

enter image description here

1
What makes you think it is not working? Keep in mind that sync is asynchronous. Is there a particular problem you are trying no solve by forcing a sync? - Dmitry Streblechenko
Because my calendars sync hasn't changed. Sure, i edited so you can understand better. - Eñaut
Are you saying the items are created locally but are not synchronized? Or are you saying you are creating an appointment with attendees and expect it to be automatically sent to the attendees? - Dmitry Streblechenko
Yes that's it, sorry if I my explanations aren't clear! They aren't synchronized with the exchange server. So I don't get them when I use EWS to get shared forder's appointments. That's why I try to force the sync. - Eñaut
I edited again, I found the a button that does it manually, I just need to find how to do it programmatically. - Eñaut

1 Answers

0
votes

I finally found a way to synchronize Outlook application's locally shared calendars with the exchange server version (actually it does a "send").

The VB.NET code below progratically opens each shared calendar and then simulate the click on "update calendar" button.


        Dim app As New Outlook.Application
        Dim ns As Outlook.NameSpace
        Dim objExpl As Outlook.Explorer
        Dim recip As Outlook.Recipient
        Dim olPane As Outlook.NavigationPane
        Dim olModule As Outlook.NavigationModule
        Dim olGroup As Outlook.NavigationGroup
        Dim navFoldersCount As Integer

        ns = app.GetNamespace("MAPI")
        objExpl = app.ActiveExplorer

        For k = 1 To ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Folders.Count
            Try
                'Try catch allows to exclude non-shared calendars to work only with share ones
                recip = ns.CreateRecipient(ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Folders.Item(k).Name)
                recip.Resolve()
                If recip.Resolved Then
                    objExpl.CurrentFolder = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderCalendar)
                    'accessing to the shared calendars creates their "Calendar - [email protected]" clone.
                    If Not objExpl Is Nothing Then
                        'Simulate the click on "UpdateFolder button
                        objExpl.CommandBars.ExecuteMso("UpdateFolder")
                    End If
                End If
            Catch

            End Try
        Next

        olPane = ns.Application.ActiveExplorer.NavigationPane
        olModule = olPane.Modules.GetNavigationModule(Outlook.OlNavigationModuleType.olModuleCalendar)
        olGroup = olModule.NavigationGroups.GetDefaultNavigationGroup(Outlook.OlGroupType.olPeopleFoldersGroup)

        'Removing calendar clones from the navigation pane
        navFoldersCount = olGroup.NavigationFolders.Count
        For i = navFoldersCount To 1 Step -1
            If (olGroup.NavigationFolders.Item(i).DisplayName.Contains("Calendar - ")) Then
                olGroup.NavigationFolders.Remove(olGroup.NavigationFolders.Item(i))
            End If
        Next