Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
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....

C#
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
Updated 23-May-12 0:01am
v2

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[^]
 
Share this answer
 
Comments
Tejas Vaishnav 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 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 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 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 25-May-12 1:42am    
have you use a Office development using VS2008/VS2010 and VSTO 3.0
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.

C#
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();
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900