How to open Inbox, Calendar, Create Appointment did it with OLEHi RFobert

This forum is meant for examples of X# code.

rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

How to open Inbox, Calendar, Create Appointment did it with OLEHi RFobert

Post by rn@warner-it.com »

Now I seem to have a problem with the Ole does anyone know another solution I am pasting the code I had before
I would greatly appreciate it if someone can help me get this working again any ideas ???
FUNCTION Calendar() AS VOID
// Add event handling code here
/* LOCAL objOL AS OBJECT
LOCAL objNS AS OBJECT
LOCAL objCalendar AS OBJECT
LOCAL objExplorer AS OBJECT


objOL := OleAutoObject{"Outlook.Application"}
objNS := objOL:GetNamespace("MAPI")
objCalendar := objNS:GetDefaultFolder(9)
objExplorer := objCalendar:GetExplorer
objExplorer:Activate()
*/
RETURN

FUNCTION Notes() AS VOID
// Add event handling code here
/*
LOCAL objOL AS OBJECT
LOCAL objNS AS OBJECT
LOCAL objContact AS OBJECT
LOCAL objExplorer AS OBJECT


objOL := OleAutoObject{"Outlook.Application"}
objNS := objOL:GetNamespace("MAPI")
objContact := objNS:GetDefaultFolder(12)
objExplorer := objContact:GetExplorer
objExplorer:Activate()

*/
RETURN


FUNCTION ContactClick() AS VOID

/*
LOCAL oApp AS Microsoft.Office.Interop.Outlook.Application
LOCAL objOL AS OBJECT
LOCAL objNS AS OBJECT
LOCAL objContact AS OBJECT
LOCAL objExplorer AS OBJECT


objOL := OleAutoObject{"Outlook.Application"}
objNS := objOL:GetNamespace("MAPI")
objContact := objNS:GetDefaultFolder(10)
objExplorer := objContact:GetExplorer
objExplorer:Activate()
*/
RETURN
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

This Code also does not work Hope to hear from someone !!! Thanks

Post by rn@warner-it.com »

FUNCTION AddOutlookContact() AS VOID
LOCAL outApplication AS Microsoft.Office.Interop.Outlook.Application
*' Get the namespace and the logon.
LOCAL outNamSpace AS Microsoft.Office.Interop.Outlook.NameSpace
*' Create a new contact item.
LOCAL NewContact AS Microsoft.Office.Interop.Outlook.ContactItem
// Create an Outlook application.

// Get the namespace and the logon.
outApplication.GetNamespace("MAPI")
outApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olContactItem)
outNamspace.Logon("Outlook",NULL,TRUE,TRUE)


// Set some common properties.
NewContact:FirstName := _OutlookFnamecontact
NewContact:FullName := _OutlookSNamecontact
NewContact:Title := _OutlookFunction
NewContact:Birthday := Convert.ToDateTime("5/4/1969")
NewContact:CompanyName := M_Custname
NewContact:Department := "Development"
* NewContact.Body := "Sample"
*NewContact.FileAs := "Authorcode"
NewContact:Email1Address := _OutlookEmailcontact
NewContact:BusinessTelephoneNumber := _OutlookTel
NewContact:MobileTelephoneNumber := _OutlookMobile
NewContact:MailingAddress := _OutlookEmailcontact
NewContact:Subject := "Contact created from X#"
NewContact:JobTitle := _OutlookFunction

NewContact:Save()
NewContact:Display(TRUE)

*oApp := Nothing
*outNamSpace := Nothing
*NewContact := Nothing

RETURN
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

This Code also does not work Hope to hear from someone !!! Thanks

Post by Chris »

Please explain what do you mean by "does not work". Do you get a compiler error, a runtime error? When? Does is just not save the contact? Something else fails?
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

How to open Inbox, Calendar, Create Appointment did it with OLE

Post by wriedmann »

Hi Raymond,
why do you try with OleAutoObject? This is VO code and AFAIK does not works in X#.
You need to rewrite that code (in a much simpler manner) using the Microsoft.Office.Interop.Outlook library, like the one I have posted to your other message.
Wolfgang
P.S. it does not helps open up more threads for a similar issue. Open up one and wait until someone is able to help you.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

How to open Inbox, Calendar, Create Appointment did it with OLE

Post by rn@warner-it.com »

Hi Wolfgang,
Thanks for your advise will do in future I sent you a reply regarding the first code you sent me I get a compile error do you know the reason I am using exactly what you did only with more fields.

Thanks
Raymond
George
Posts: 106
Joined: Thu Nov 05, 2015 9:17 am

How to open Inbox, Calendar, Create Appointment did it with OLE

Post by George »

In X#, you may use Microsoft.Office.Interop.Outlook.

Example for Outlook Contacts:

USING Microsoft.Office.Interop.Outlook


LOCAL outlook AS Microsoft.Office.Interop.Outlook.Application
LOCAL outlookNS AS Microsoft.Office.Interop.Outlook.NameSpace

outlook := Microsoft.Office.Interop.Outlook.Application{}
outlookNS := outlook:GetNamespace("MAPI")

LOCAL oContactFolder := SELF:outlookNS:PickFolder() AS MAPIFolder
IF oContactFolder == NULL
RETURN
ENDIF

FOREACH oFolderFound AS MAPIFolder IN oContactFolder:Folders
IF oFolderFound:DefaultItemType == Microsoft.Office.Interop.Outlook.OlItemType.olContactItem
//do something
ENDIF
NEXT

George
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

How to open Inbox, Calendar, Create Appointment did it with OLE

Post by robert »

Raymond,
In .Net the recommended way to use com is not to use the oleautoobject class but to use a refernece to the interop library that is created when you add a com reference to your project, or to use a "primary interop assembly", a pre installed interop library that you will find in the first page of add reference dialog.
This approach works much better than the oleautoobject class.
If you look in the turorials in the documentation you should also find an example of how to automate excel that way.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

How to open Inbox, Calendar, Create Appointment did it with OLEHi RFobert

Post by rn@warner-it.com »

Hi Robert,
Thanks for the Info I will do so.

Thanks
Raymond
rn@warner-it.com
Posts: 46
Joined: Mon Mar 04, 2019 4:41 pm

How to open Inbox, Calendar, Create Appointment did it with OLE

Post by rn@warner-it.com »

Hi George,
I will try your code and let you know how I get on thanks for your help.

Regards,
Raymond
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to open Inbox, Calendar, Create Appointment did it with OLEHi RFobert

Post by ic2 »

Hello Raymond,

I am finalizing my program to read cells from an Excel spreadsheet. I hope to have it ready tomorrow and I'll publish it here so anyone wanting to do some Office automation should have a good starting point.

Dick
Post Reply