Solved

Import contact from Microsoft Outlook in .net project

Posted on 2011-09-11
8
254 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Technology Partners: 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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 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