Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Office VSTO Events Outlook AddIn , +
I have develop one Custom addin for Outlook.
 
and i have put some custome button on Outlook Ribbon bar also.
 
now what is my problem is, i want to call one method declared on ThisAddin class (which is by default created by Addin), from by custom button's(which is placed on RibbonBar) Click event.
 

for this right now i am using a new instance of ThisAddin class to call that method, but i will creating some issues. so i want to know any other method with out creating new instance of ThisAddin class can i call my method from Button Click event.
 
or can i call Send Item event from by Button Click event.
 

what i am using right now is like this....
 
private void btnProtect_Click(object sender, RibbonControlEventArgs e)
{
    using (ThisAddIn _addIn = new ThisAddIn())
    {
        //Here what i do is Create one new Instance of ThisAddin Class
        //And Access it's ItemSend() method throught it.
        _addIn.ItemSend();
    
    }
}
 

What i want is with out createing any new instance i want to call that method from my ribbon -> button -> click event
 
OR
 
I want to Fire a Application.ItemSend event from Ribbon Control Button Click Event.

 
please provide your valuable suggestions.
Posted 23-May-12 0:33am
Edited 23-May-12 1:01am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Sounds like you want to use a static class or static member function:
 
http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx[^]
  Permalink  
Comments
Tejas_Vaishnav at 24-May-12 0:19am
   
I appriciate your try, but that not what i want.
while developing a Office addin in some case we want to access the amin addin calss methods or events from custom menubar's or ribbonbar's. and that what i want.
TRK3 at 24-May-12 13:19pm
   
I'm confused about what you want to do.
 
If you don't want to create a new instance, then you obviously want to refer to an existing instance.
 
Is there only one instance or are there multiple instances?
 
If there is only one, then a static class solves your problem.
 
If there are multiple instances, then which instance do you want to refer to?
Tejas_Vaishnav at 25-May-12 1:40am
   
ThisAddin Class is already given by the VSTO template. so we can not make it as a static or sealed class.
Tejas_Vaishnav at 25-May-12 1:41am
   
and the Ribbon bar is attached inside that ThisAddin Class automatically by setting some property of Ribbon Contarol. and i want to call a Send button click event from my ribbon bar button click.
Tejas_Vaishnav at 25-May-12 1:42am
   
have you use a Office development using VS2008/VS2010 and VSTO 3.0
TRK3 at 25-May-12 13:34pm
   
I haven't done VSTO / Office development, but the documentation says that you should not instantiate the class yourself and that it is instantiated when your addin is loaded.
 
I would think it should be available as Application.thisAddin or Globals.thisAddin or something like that... Isn't it?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Finally i found the solution for this.
what i do for this is to access the mail item and use mail items send() method so it will fire Application_Item Send event automatically.
 
like this.
 
 
private void btnProtect_Click(object sender, RibbonControlEventArgs e)
{
    //FormFactory is User Defined Class to store local Variables
    //Here i already store my MailItem Object
    FormFactory.Instance.OutlookMailItem.Send();
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 275
1 DamithSL 265
2 CPallini 235
3 Maciej Los 185
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 30 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100