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("", 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 = " "
            oCt.BusinessHomePage = " "
            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?
    • Moved by Amanda Zhu Wednesday, October 2, 2013 9:04 AM
    Tuesday, October 1, 2013 1:41 PM

All replies

  • Hello,

    I have moved this thread to Outlook for Developers forum for better response.

    Thanks,


    Amanda Zhu <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 2, 2013 9:04 AM
  • Which line of your code raises that error?

    Does your app run as a regular GUI app?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, October 2, 2013 3:27 PM