Outlook Synchronization ?

Administrator

VB.NET Forum Admin
Joined
Jun 3, 2004
Messages
1,462
Programming Experience
10+
Hello,

I built a Contacts style area and want to build a two way sync with Outlook. This is to allow users to sync IN their Outlook Contacts and take contacts they created in my Winforms app and sync TO Outlook.

Anyone worked with Outlook sync from a VB.NET application? Anyone know of sample code, etc.? I prefer it to be generic Outlook, i.e. they can sync with any of the recent three versions of Outlook and are not locked into one specific version such as Outlook 2007.

Thank you.
 
Here's some basic code to get/add contacts:
VB.NET:
Dim App As Outlook.Application = New Outlook.Application
Dim NS As Outlook.NameSpace = App.GetNamespace("MAPI")
NS.Logon()

Dim Contacts As Outlook.MAPIFolder = NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
Dim sb As New System.Text.StringBuilder
For Each ct As Outlook.ContactItem In Contacts.Items
    sb.AppendFormat("{0}, {1}", ct.FullName, ct.Email1Address)
    sb.AppendLine()
Next
MsgBox(sb.ToString)

Dim newct As Outlook.ContactItem = App.CreateItem(Outlook.OlItemType.olContactItem)
newct.FullName = "new fullname"
newct.Email1Address = "new@email.com"
newct.Save()

NS.Logoff()
App.Quit()
I think you need to create an AddIn to prevent the security warning dialogs.

Runtime.InteropServices.Marshal.ReleaseComObject is used some cases to prevent memory leaks.
 
Back
Top