[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Import contact from Microsoft Outlook in .net project

Posted on 2011-09-11
8
Medium Priority
?
268 Views
Last Modified: 2012-05-12
Hello all,

I was feeding a combo box from an access dbase with this code:

 Dim sSQL3 As String
        Dim oConnect3 As ADODB.Connection
        oConnect3 = New ADODB.Connection
        Dim oRST3 As ADODB.Recordset
        oRST3 = New ADODB.Recordset


        sSQL3 = "SELECT DISTINCT[Name]FROM [Clients]'"

        oConnect3.Open("Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=" & Form4.base_de_donnee.Text)

        Me.client.Items.Add("")
        oRST3.Open(sSQL3, oConnect3)

        If Not oRST3.EOF Then
            oRST3.MoveFirst()
            Do Until oRST3.EOF
                Me.client.Items.Add(oRST3("Name").Value)
                oRST3.MoveNext()
            Loop

        End If
        Exit Sub
MyErrHandler:
        MsgBox("Connectez-vous sur votre base de données la plus à jour.", _
        vbCritical, _
        "Connection à la basse de donnée Access")
        Me.Close()
        Form4.Show()

Open in new window


But now, i would like to know if i can feed it from my contact list from Outlook, instead of always exporting it in access?

This was to feed my combo box but after, i was having a button to put out the rest of the information from that contact into diffrent text box like this:

Dim sSQL1 As String
        Dim oRST1 As ADODB.Recordset
        oRST1 = New ADODB.Recordset
        Dim oConnect1 As ADODB.Connection
        oConnect1 = New ADODB.Connection


        oConnect1.Open("Provider=Microsoft.ACE.OLEDB.12.0;" & _
       "Data Source=" & Form4.base_de_donnee.Text)


        sSQL1 _
                = " SELECT [Name],[Phone],[Email]" _
                & " FROM [Clients]" _
                & " WHERE Name = '" & client.Text & "'"

        oRST1.Open(sSQL1, oConnect1)

        If oRST1.BOF = False Then

            If Not String.IsNullOrEmpty("Name") Then
                oRST1.Filter = "Name = '" & client.Text & "'"

                'Phone
                telephone.Text = oRST1.Fields.Item(1).Value.ToString

                'Email
                courriel.Text = oRST1.Fields.Item(2).Value.ToString

            End If
        End If

Open in new window


Thanks again for your help.
0
Comment
Question by:Wilder1626
  • 4
  • 3
8 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 36520328
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 36520339
Hello plusone3055

thanks but is that C++? not .net?

i have also found this: Microsoft Outlook Integration with C#.NET

but i dont use C++.

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 36520396
I have found this code but it only open the first outlook contact, directly in Outlook.

I want to populate my combobox or could be a list box and see all my contact.

 ' Create Outlook application.
        Dim oApp As Outlook.Application = New Outlook.Application()

        ' Get NameSpace and Logon.
        Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
        oNS.Logon("Outlook", Missing.Value, False, True) ' TODO:

        ' Get the first contact from the Contacts folder.
        Dim cContacts As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
        Dim oItems As Outlook.Items = cContacts.Items

        Dim oCt As Outlook.ContactItem

        Try

            oCt = oItems.GetFirst()


            ' Display some common properties.
            Console.WriteLine(oCt.FullName)
            Console.WriteLine(oCt.Title)
            Console.WriteLine(oCt.Birthday)
            Console.WriteLine(oCt.CompanyName)
            Console.WriteLine(oCt.Department)
            Console.WriteLine(oCt.Body)
            Console.WriteLine(oCt.FileAs)
            Console.WriteLine(oCt.Email1Address)
            Console.WriteLine(oCt.BusinessHomePage)
            Console.WriteLine(oCt.MailingAddress)
            Console.WriteLine(oCt.BusinessAddress)
            Console.WriteLine(oCt.OfficeLocation)
            Console.WriteLine(oCt.Subject)
            Console.WriteLine(oCt.JobTitle)


        Catch

            Console.WriteLine("an error occurred")

        Finally

            ' Display
            'oCt.Display(True)

            ListView1 = oCt.FullName.ToString
            ' Log off.
            oNS.Logoff()

            ' Clean up.
            oApp = Nothing
            oNS = Nothing
            oItems = Nothing
            oCt = Nothing

        End Try

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 36526307
After this


Dim oItems As Outlook.Items = cContacts.Items

        Dim oCt As Outlook.ContactItem


try this

For Each oCt in oItems
     Console.Writeline(oCt.FullName)
     'OR
     Combobox1.Items.Add(oCt.FullName)
Next
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 36526447
Oh perfect for :

For Each oCt in oItems
     Console.Writeline(oCt.FullName)
     'OR
     Combobox1.Items.Add(oCt.FullName)
Next

Open in new window


Now i just need to fix the second part.

If   Combobox1.Items =  ? then
courriel.value = oCt.Email1Address

but i cant make it work.



0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36532037
Not sure what the below is expected to do. Can you explain?


If   Combobox1.Items =  ? then
courriel.value = oCt.Email1Address
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 36532452
Well that part was just to show what i was trying to do.


Now, it works great.
Thanks for your help.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36532525
Glad to help :-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question