How to access Application property in VSTO Outlook add-in outside of ThisAddIn class?

Since you can have single Instance of ThisAddIn you can have a static variable to access Application form outside... FYI when you add Outlook-AddIn VSTO project,instance of ThisAddIn will be available as static member in static class Globals


It is actually bad practice to place static variables in the ThisAddIn in order to reference from around your code.

According to this answer https://stackoverflow.com/a/46493968/2068626, the Outlook Application object is a singleton so it would be preferred to do your own second suggestion

var app = new Outlook.Application();

Since this is a Outlook VSTO add-in there is zero risk of starting Outlook since it by definition will be running. If you use this method from within another Office application you would start Outlook only if Outlook is not currently running.

For completeness sake, all other shared models should use a form of Dependency Injection so there is no strong coupling in your code.

Using these two approaches it would also be easier (possible) for you to refactor your code and other classes out into a separate library for easier reuse across your VSTO projects or even a Nuget Package.


Comments

  1. Braden

    • 2016/10/13

    Since you can have single Instance of ThisAddIn you can have a static variable to access Application form outside FYI when you add 

  2. Bellamy

    • 2018/7/19

    ThisAddIn class created with new Outlook VSTO C# project has a Application property that you can use to among other things get access to Outlook folders and items. The problem is that you can easily use it when you're inside of ThisAddIn class but there's no easy access to it from other classes in the project.

  3. Daxton

    • 2017/6/26

    Since you can have single Instance of ThisAddIn you can have a static variable to access Application form outside FYI when you add Outlook-AddIn VSTO 

  4. Aldo

    • 2021/4/12

    For more information about the Globals class, see Global access to objects in Office projects. Applies to: The information in this topic applies to VSTO Add-in projects for Outlook. For more information, see Features available by Office application and project type. Access form regions that appear in a specific Outlook Inspector window

  5. Niko

    • 2015/6/8

    ThisDocument property. The ThisAddIn class in a VSTO Add-in project. You can access this object by using the Globals.ThisAddIn property 

  6. Bektashi

    • 2016/12/20

    The ThisAddIn class in a VSTO Add-in project. You can access this object by using the Globals.ThisAddIn property. All Ribbons in your project that you customized by using the Ribbon Designer. You can access the Ribbons by using the Globals.Ribbons property. For more information, see Access the Ribbon at run time.

  7. Yisroel

    • 2020/11/23

    For more information, see Expose classes to out-of-process clients. Set the Register for COM interop property in the project where you define 

  8. Yahya

    • 2016/5/6

    To help avoid security warnings when you use restricted properties and methods, make sure that your VSTO Add-in obtains Outlook objects from the Application field of the ThisAddIn class in your project. For more information about this field, see Program VSTO Add-ins.

  9. Kairo

    • 2015/11/18

    In this article, Darko Martinovic demonstrates how to use C# to create VSTO Add-ins are associated with the application itself and 

  10. Emmett

    • 2015/5/3

    For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1 public void Ribbon_Load (Office.IRibbonUI ribbonUI) { this .ribbon = ribbonUI; } #endregion. Thanks but I did work out my issue in the end. Its related to using the visual ribbon designer.

  11. Jesiah

    • 2017/6/24

    How to access Application property in VSTO Outlook add-in outside of ThisAddIn class? 4 · VSTO Word activate ribbon tab · 7 · How to have a VSTO 

  12. Johnathan

    • 2015/8/6

    In the Solution Explorer, right-click the OfficeAddInSetup project and select Properties. The OfficeAddInSetup Property Pages dialog box appears. Click the Prerequisites button. In the Prerequisites dialog box, select the correct version of the .NET Framework and the Microsoft Visual Studio Tools for Office Runtime.

  13. Orion

    • 2019/12/13

    I have created an Outlook add-in project, but get a cast exception when I am trying to create the Application from code outside the ThisAddIn class.

  14. Ulises

    • 2015/8/20

    To develop VSTO Add-ins for Microsoft Office Outlook, you can interact with Application object, use the Application field of the ThisAddIn class in your 

  15. Aziel

    • 2020/12/8

    Start by creating a VSTO Add-in project for Outlook. outside the ThisAddIn class (for Visual C#, add this code inside the OutlookMailItemTaskPane 

  16. Jagger

    • 2021/2/10

    addin and methods/properties in it to outside code. COMAddIn)app. I was hoping that I will get a reference to VSTO AddIn using addin 

Comments are closed.

Recent Posts