Bear23

I want to add a button when the new message box is open.

I tried everything and I cannot get it to work.

I get errors like:

An unhandled exception occurred in your application. Contact your administrator.....

I cannot seem to figure out what i am missing.

Any ideas.

I am using Outlook 2003, vs2005, c#



Re: Visual Studio Tools for Office Add command button to the send email screen

BillyD

Are trying to place a "Button" or a commandbar type

if it is a CommandBar type you can try something in the AppStartup event add something like...

_inspectors = this.Inspectors;

_inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler( _inspectors_NewInspector );

in the newly added event handler you can pop a messagebox to find out if the inspector is of what you need and if it is, call your add new commandbarbutton method to populate the form.

Hope this helps





Re: Visual Studio Tools for Office Add command button to the send email screen

Bear23

All I want to do is add a button to the toolbar of the place where a user creates and sends a new email. Worse case scenerio it could even be in the toolbar for just outlook..

Either way nothing seems to work..

I even found this link and gave this part of the code a try.

http://blogs.msdn.com/dancre/archive/2004/03/21/93712.aspx

CommandBars commandBars = applicationObject.ActiveExplorer().CommandBars;

// Create a toolbar button on the standard toolbar that calls ToolbarButton_Click when clicked

try

{

// See if it already exists

this.toolbarButton = (CommandBarButton)commandBars["Standard"].Controls["Hello"];

}

catch(Exception)

{

// Create it

this.toolbarButton = (CommandBarButton)commandBars["Standard"].Controls.Add(1, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);

this.toolbarButton.Caption = "Hello";

this.toolbarButton.Style = MsoButtonStyle.msoButtonCaption;

}

this.toolbarButton.Tag = "Hello Button";

this.toolbarButton.OnAction = "!<MyAddin1.Connect>";

this.toolbarButton.Visible = true;

this.toolbarButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.OnToolbarButtonClick);

nothing seems to work. Could you post something

Thanks. I have tried everyplace and used tons of samples and nothing. I even tried to download the microsoft outlook sample but there code will not even open up on my machine.

I have vs2005, and I think its vsto 2005 se, because the vsto 2005 was not part of the vs2005 professional that i have.





Re: Visual Studio Tools for Office Add command button to the send email screen

Sue Mosher - Outlook MVP

ActiveExplorer is the main Outlook window. As BillyD pointed out, the windows that display individual items are Inspector windows, not Explorer windows.



Re: Visual Studio Tools for Office Add command button to the send email screen

Bear23

can someone please post what I need to do to get this to work..



Re: Visual Studio Tools for Office Add command button to the send email screen

Sue Mosher - Outlook MVP

I don't write C# code, but Helmut's Inspector sample at http://www.outlookcode.com/codedetail.aspx id=797 has helped a lot of people with this.



Re: Visual Studio Tools for Office Add command button to the send email screen

Robert Green

Try this



public Outlook.Inspectors openInspectors;
private Office.CommandBar helloCommandBar;
private Office.CommandBarButton helloCommandBarButton;

private void ThisApplication_Startup(object sender, System.EventArgs e)
{
openInspectors = this.Inspectors;
openInspectors.NewInspector += new
Outlook.InspectorsEvents_NewInspectorEventHandler(
Inspectors_NewInspector);
}

private void Inspectors_NewInspector(Outlook.Inspector inspector)
{
// Get a reference to the Inspector main menu bar
helloCommandBar = inspector.CommandBars.Add(
"Hello CommandBar", Office.MsoBarPosition.msoBarTop,
Type.Missing, true);
if (helloCommandBar != null)
{
helloCommandBar.Visible = true;
}
// Add a button to the Inspector main menu bar
helloCommandBarButton = ((Office.CommandBarButton)
(helloCommandBar.Controls.Add(
Office.MsoControlType.msoControlButton,
Type.Missing, Type.Missing, Type.Missing, true)));
helloCommandBarButton.Caption = "Say hello";
helloCommandBarButton.Style =
Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption;
helloCommandBarButton.Visible = true;
// Associate the Click event with the
// helloCommandBarButton_Click method
helloCommandBarButton.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(
addCustomerInfoCommandBarButton_Click);
}

public void addCustomerInfoCommandBarButton_Click(
Office.CommandBarButton ctrl, ref bool CancelDefault)
{
MessageBox.Show("Hello");
}

Robert





Re: Visual Studio Tools for Office Add command button to the send email screen

Bear23

first I am getting an error on this line...

openInspectors = this.Inspectors;

it is giving the error for the line this.Inspectors

if i comment this out and then run the project outlook opens but then i get this error:

OutlookAddin2.dll.manifest is the title of the error box.

the error message is:

An unhandled exception occurred in your application. Contact your administrator or the author of this document for further assistance.





Re: Visual Studio Tools for Office Add command button to the send email screen

Robert Green

What is the error you get on that line

Robert





Re: Visual Studio Tools for Office Add command button to the send email screen

Bear23

I cannot debug all I have when I hit the detail button is this:

Object reference not set to an instance of an object.


************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at OutlookAddIn2.ThisAddIn.ThisAddIn_Startup(Object sender, EventArgs e) in C:\OutlookAddIn2\ThisAddIn.Designer.cs: line 20
at Microsoft.Office.Tools.AddIn.OnStartup()
at OutlookAddIn2.ThisAddIn.FinishInitialization() in C:\OutlookAddIn2\ThisAddIn.Designer.cs:line 70
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecutePhase(String methodName)
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteCustomizationStartupCode()
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.ExecuteEntryPointsHelper()
at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.Microsoft.VisualStudio.Tools.Applications.Runtime.IExecuteCustomization2.ExecuteEntryPoints()


************** Loaded Assemblies **************


also remember the line:

openInspectors = this.Inspectors;

had to be commented out because the error for this line is:

Error 1 'OutlookAddIn2.ThisAddIn' does not contain a definition for 'Inspectors' C:\OutlookAddIn2\ThisAddIn.cs 19 34 OutlookAddIn2





Re: Visual Studio Tools for Office Add command button to the send email screen

Robert Green

Well I sure don't understand how ThisAddIn could not contain a definition for Inspectors.

When I create this VSTO Outlook Add-in and go into ThisApplication.cs, I see the following:

using Outlook = Microsoft.Office.Interop.Outlook;

Then I add the following declaration:

public Outlook.Inspectors openInspectors;

[This could have been private. I copied this from another project where it is public.]

Notice that Inspectors is in green, so C# knows it is valid.

Then I add the following to the Startup procedure:

openInspectors = this.Inspectors;

When I type the dot, I see Inspectors in the IntelliSense. Do you not

Robert





Re: Visual Studio Tools for Office Add command button to the send email screen

Bear23

here is the code.....Also I noticed that mine is thisaddin.cs Am I missing something for install

using System;

using System.Windows.Forms;

using Microsoft.VisualStudio.Tools.Applications.Runtime;

using Outlook = Microsoft.Office.Interop.Outlook;

using Office = Microsoft.Office.Core;

namespace OutlookAddIn1

{

public partial class ThisAddIn

{

public Outlook.Inspectors openInspectors;

private Office.CommandBar helloCommandBar;

private Office.CommandBarButton helloCommandBarButton;

private void ThisAddIn_Startup(object sender, System.EventArgs e)

{

openInspectors = this.Inspectors;

openInspectors.NewInspector += new

Outlook.InspectorsEvents_NewInspectorEventHandler(

Inspectors_NewInspector);

}

private void Inspectors_NewInspector(Outlook.Inspector inspector)

{

// Get a reference to the Inspector main menu bar

helloCommandBar = inspector.CommandBars.Add(

"Hello CommandBar", Office.MsoBarPosition.msoBarTop,

Type.Missing, true);

if (helloCommandBar != null)

{

helloCommandBar.Visible = true;

}

// Add a button to the Inspector main menu bar

helloCommandBarButton = ((Office.CommandBarButton)

(helloCommandBar.Controls.Add(

Office.MsoControlType.msoControlButton,

Type.Missing, Type.Missing, Type.Missing, true)));

helloCommandBarButton.Caption = "Say hello";

helloCommandBarButton.Style =

Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption;

helloCommandBarButton.Visible = true;

// Associate the Click event with the

// helloCommandBarButton_Click method

helloCommandBarButton.Click += new

Office._CommandBarButtonEvents_ClickEventHandler(

addCustomerInfoCommandBarButton_Click);

}

public void addCustomerInfoCommandBarButton_Click(

Office.CommandBarButton ctrl, ref bool CancelDefault)

{

MessageBox.Show("Hello");

}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)

{

}

#region VSTO generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InternalStartup()

{

this.Startup += new System.EventHandler(ThisAddIn_Startup);

this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);

}

#endregion

}

}





Re: Visual Studio Tools for Office Add command button to the send email screen

Robert Green

You are not missing anything. My code was written for the initial VSTO 2005. I just tried this in VSTO 2005 SE and get the same results you do. Try this instead:

openInspectors = this.Application.Inspectors;

In the original VSTO 2005 "this" refers to Outlook itself. In VSTO 2005 SE, "this" refers to the addin. Since Inspectors belongs to Outlook, you need to use this.Application.

My bad for posting "previous version" code.

Robert





Re: Visual Studio Tools for Office Add command button to the send email screen

Robert Green

To follow up on this and clarify, in the original VSTO 2005 you had one template for Outlook Add-ins. When you select this, your project has a ThisApplication class and "this" refers to Outlook, which has an Inspectors collection.

If you have only VSTO 2005 SE, your case, you still have one template for Outlook 2003 Add-ins. When you select this, your project has a ThisAddin class and "this" refers to the add-in, not Outlook. To get to Outlook, you use this.Application.

If you install VSTO 2005 SE over VSTO 2005, you get both choices. Select Office in the Project Types list and Outlook Add-in in the templates list and you will have a ThisApplication class. Select 2003 Add-ins in the Project Types list and Outlook Add-in in the templates list and you will have a ThisAddin class.

Robert





Re: Visual Studio Tools for Office Add command button to the send email screen

Bear23

so far this is working great, but 2 things:

1. everytime I open the create message it keeps adding the button.

2. is there a way to make it so that when you click the button a dialog box appear, and a form too

Thank you so much for your help. I do have the SE because the first vsto wasn't avaiable for free.