Solved

Import contact from Microsoft Outlook in .net project

Posted on 2011-09-11
8
242 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

864 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now