IntroductionIn this article, we will learn how to create a simple Hello World browser add-in for Microsoft’s applications that supports add-in. A list of such applications is given here:
In this article, we will take Microsoft Outlook as an example. Prerequisites:You must have the following …
Creating the Add-in
Add-In WizardWhen the Add-in wizard starts, press Next... Select programming language (example C#), press Next. Select applications in which you want to host your add-in, press Next. Provide add-in name and description, press Next. Choose add-in options, press Next. Press Finish. Setup ProjectsTwo projects will be added automatically.
Creating the Browser Form
void go()
{
try
{
stbPanel1.Text="Trying to open "+tbURL+"..." ;
object obj=new object ();
browser.Navigate(tbURL.Text,ref obj,ref obj,ref obj,ref obj);
}
catch(Exception ex)
{
//error hanlder here......
}
}
Call this function on the Programming for Add-in ConnectionInstall PIAs and add a reference to the following DLL: Microsoft.Office.Interop.Outlook.DLL. There will be a file connect.cs in the add-in project, open it. Declare the following items globally: //for Outlook Express you can mention here word, power point.
private Microsoft.Office.Interop.Outlook.Application applicationObject;
private object addInInstance;
private CommandBarButton btnLaunch;
In the function public void OnStartupComplete(ref System.Array custom)
{
CommandBars commandBars =
applicationObject.ActiveExplorer().CommandBars;
try
{
//if will be good if button exist use it
btnLaunch= (CommandBarButton)
commandBars["Standard"].Controls["HelloWorld"];
}
catch
{
//if error occur
btnLaunch = (CommandBarButton)
commandBars["Standard"].Controls.Add(1,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value);
btnLaunch.Caption = "Hello World Browser!";
btnLaunch.Style = MsoButtonStyle.msoButtonCaption;
}
//use tag for quick access of button.
btnLaunch.Tag = "This is Hello World Browser!";
btnLaunch.OnAction = "!<EMAILSTATSADDIN.CONNECT>";
btnLaunch.Visible = true;
btnLaunch.Click += new
_CommandBarButtonEvents_ClickEventHandler(
btnLaunch_Click);
}
In the function public void OnBeginShutdown(ref System.Array custom)
{
//delete our button...
CommandBars commandBars = applicationObject.ActiveExplorer().CommandBars;
try
{
//remove on unload...
commandBars["Standard"].Controls["HelloWorld"].Delete(
System.Reflection.Missing.Value);
}
catch(System.Exception ex)
{
//code to show/log error...
}
}
Write the following code in the private void btnLaunch_Click(CommandBarButton Ctrl,
ref bool CancelDefault)
{
try
{
frmHelloWorld objfrmHelloWorld=new frmHelloWorld ();
objfrmHelloWorld.Show();
}
catch(Exception ex)
{
//code to show or log error...
}
}
Rebuild and InstallationRight click on the setup project, click Rebuild, and it will automatically rebuild the add-in and the setup project. Then, right click on the setup project and click Install. RunningRun Microsoft Outlook, and you will see “Hello World Browser!” on the toolbar. Click on it and your add-in will start. As you can see here... Known IssuesAfter uninstallation, the “Hello World Browser!” button is not removed from the Outlook toolbar. |
Build Your Own Add-in For Microsoft Office Using .NET
最新推荐文章于 2024-10-15 10:58:36 发布