Solved

Import contact from Microsoft Outlook in .net project

Posted on 2011-09-11
8
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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