none
How to create an application windows form, using the visual studio 2012, for office 365 ? RRS feed

  • Question

  • Hi friends,

    I'm creating a windows application, using the visual studio 2012, to add contacts for ms-outlook office 365. In my application, I want to access my local outlook application to insert persons in my contact folder. Look my code below:

    Imports System.Diagnostics
    Imports System.Linq
    Imports System.Reflection
    Imports System.Runtime.InteropServices
    Imports Outlook = Microsoft.Office.Interop.Outlook

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

                ' Create an Outlook application.
                Dim oApp As Outlook.Application


                'Check if there is an Outlook process running. 
                If Process.GetProcessesByName("OUTLOOK").Length > 0 Then

                     oApp = DirectCast(Marshal.GetActiveObject("Outlook.Application"), Outlook.Application)

                Else

                    ' If not, create a new instance of Outlook and log on to the default profile. 
                   oApp = New Outlook.Application()


                    ' Get the namespace and the logon.
                    Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")


                    ' TODO: Replace the "YourValidProfile" and "myPassword" with 
                    oNS.Logon("ExchangeCECAFE", Missing.Value, True, True)


                End If



            ' Create a new contact item.
            Dim oCt As Outlook.ContactItem = oApp.CreateItem(Outlook.OlItemType.olContactItem)


            oCt.Display(True)  'Modal

            ' Set some common properties.
            oCt.FullName = "David Pelton"
            oCt.Title = "Student"
            oCt.Birthday = Convert.ToDateTime("10/1/1982")
            oCt.CompanyName = "Fourth Coffee "
            oCt.Department = "PSS"
            oCt.Body = "Test Body"
            oCt.FileAs = "David"
            oCt.Email1Address = "abc@hotmail.com"
            oCt.BusinessHomePage = "http://www.fourthcoffee.com/"
            oCt.MailingAddress = "12345 Bellevue"
            oCt.BusinessAddress = "56789 1st. Redmond, WA 98001"
            oCt.OfficeLocation = "666 Office"
            oCt.Subject = "Hello World"
            oCt.JobTitle = "Engineer"

            ' Save it to the Contacts folder.
            oCt.Save()


            ' Display the created contact item.
            oCt.Display(True)

            ' Log off.
            oNS.Logoff()

            'oNS = Nothing

            ' Clean up.
            oApp = Nothing

            oCt = Nothing

    end sub

    THE APPLICATION ERROR

    -------------------------------------

    Exception HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

    I setting my account with administrador (I'm using windows 7), but another error ocorred with RPC.

    Somebody help-me?

    Thanks,

    Eduardo

    Tuesday, October 1, 2013 1:55 AM