0

Good day, I am trying to create an outlook addin, that retrieves fields entered in the new appointment tab when creating an outlook meeting, primarily what location they have selected.

When creating a new meeting you are able to select the room (resource) and it displays in the location field.

I need to be able to pull in that location into my C# outlook addin (VSTO) and display it as a string. I am not able to find that reference anywhere.

Everywhere i have looked they have explained how to create a new appointment from C# but not the other way around:

I am not entirely sure this is possible, But i would assume it to look something like: string location = Outlook.AppointmentItem.Resources

The closest i have found would be something like these: https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._appointmentitem.resources%28v=office.14%29.aspx And https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._appointmentitem%28v=office.14%29.aspx

But they dont seem to work. Any and all help would be appreciated.

1 Answers1

0

Use AppointmentItem.Location property. Or loop through AppointmentItem.Recipients collection and look for Recipient.Type = olBCC resources are BCC recipients).

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thankyou so much for the speedy reply Dmitry, however i get the following issue: Error CS0117 'AppointmentItem' does not contain a definition for 'location' – Crackalackin May 19 '16 at 06:14
  • Of course it does. Have you tried "Location" (note the uppercase "L:)? – Dmitry Streblechenko May 19 '16 at 06:36
  • Thanks @Dmitry, much appreciated! only having an issue with this now, i have tried to make my string static : static string LocationValue = Outlook.AppointmentItem.Location; Error CS0120 An object reference is required for the non-static field, method, or property '_AppointmentItem.Location' – Crackalackin May 19 '16 at 12:03
  • Just as the compiler error suggests, you are invoking a static property. There is no such thing in COM - you must access Location property on a particular **instance** of the Outlook.AppointmentItem object. – Dmitry Streblechenko May 19 '16 at 16:46
  • Thanks Dmitry `Outlook.AppointmentItem _loc = new Outlook.AppointmentItem(); string LocationValue = _loc.Location;` I can compile now with no errors, however i get an error during run-time: Retrieving the COM class factory for component with CLSID ...failed 80040154 Class not registered – Crackalackin May 20 '16 at 15:20
  • I have tried this: changed the platform code, however i still get the same error: http://stackoverflow.com/questions/4021796/error-80040154-class-not-registered-exception-when-initializing-vcprojectengin/4021887#4021887 – Crackalackin May 20 '16 at 15:33
  • AppointmentItem is not creatable, you need to retrieve it from Outlook. If it is being displayed, use Application.AcrtiveInspector.CurrentItem. – Dmitry Streblechenko May 20 '16 at 16:42
  • Apologies Dmitry, I understand i need to retrieve it from outlook, but i am not sure how to format the Application.ActiveInspector.CurrentItem in relation to the location/resource. Do i replace the previous object completely with the active inspector? I simply want to view the outlooks appointment's location in a string... – Crackalackin May 24 '16 at 15:05
  • I am not sure what you are asking. Application.ActiveInspector.CurrentItem.Location will give you what you want. – Dmitry Streblechenko May 24 '16 at 17:23
  • Could you give me this ActiveInspector in some code sample, because I don't understand how this works. – Crackalackin May 26 '16 at 13:07
  • I am not sure what you are having troubles with. In a VSTO addin, you can use Globals.ThisAddIn.Application to access the Outlook.Application object. Once you have Application, check that Application.ActiveInspector is not null. Cast Application.ActiveInspector.CurrentItem to ApppointmentItem object. Use ApppointmentItem.Location. – Dmitry Streblechenko May 26 '16 at 14:01