RE: VSTO 2005 Beta 2 Outlook Addin: How to create a context menu?
- From: Roosevelt Sheriff [MSFT] <RooseveltSheriffMSFT@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 25 Jul 2005 10:40:11 -0700
I would not recommend developing a solution around a context menu if you need
it to be 100% reliable. There are scenarios (such as the one you've found)
where the event does not fire thus your code to add you context menu does not
fire. The sample code checks to see if the mail item's subject contains
specific text and if so add the context menu. You should be able to just
strip this out and add it for all items. Also we cast the selectedItem as a
MailItem. If I you want to add it to other objects just try to type cast it
to other objects such as a contact or calendar item.
"David White [MSFT]" wrote:
> I like the sample thanks. My problem is similiar but my quesiton would be how
> to I get the action for all calendar items? By using your code the action
> menu would not appear the first time I right clicked but it would the second
> time. As I would expect since I added the action to the item. How do I make
> it an action for any and all calendar (or other object) entries?
>
> "Roosevelt Sheriff [MSFT]" wrote:
>
> > Here is some sample code that copies an email message using a custom menu
> > command.
> > Outlook.Explorer explorer = null;
> > private const string FOLDER_NAME = "Picnic";
> >
> > System.Collections.ArrayList selectedItems = new
> > System.Collections.ArrayList();
> >
> > private void ThisApplication_Startup(object sender,
> > System.EventArgs e)
> > {
> > explorer = this.Explorers.Application.ActiveExplorer();
> > explorer.SelectionChange += new Outlook.
> > ExplorerEvents_10_SelectionChangeEventHandler
> > (explorer_SelectionChange);
> > }
> >
> > void explorer_SelectionChange()
> > {
> > selectedItems.Clear();
> >
> > foreach (object selectedItem in explorer.Selection)
> > {
> > Outlook.MailItem mailItem = selectedItem as Outlook.MailItem;
> >
> > if (mailItem != null)
> > {
> > if (mailItem.Subject.Contains(FOLDER_NAME))
> > {
> > Outlook.Action newAction = mailItem.Actions[
> > string.Format("Copy to {0} Folder", FOLDER_NAME)];
> >
> > if (newAction == null)
> > {
> > newAction = mailItem.Actions.Add();
> > newAction.Name = string.Format
> > ("Copy to {0} Folder", FOLDER_NAME);
> > newAction.ShowOn =
> > Outlook.OlActionShowOn.olMenu;
> > newAction.Enabled = true;
> > mailItem.Save();
> > }
> >
> > mailItem.CustomAction += new Outlook.
> > ItemEvents_10_CustomActionEventHandler
> > (mailItem_CustomAction);
> >
> > selectedItems.Add(mailItem);
> > }
> > }
> > }
> > }
> >
> > void mailItem_CustomAction(object Action, object Response,
> > ref bool Cancel)
> > {
> > try
> > {
> > Outlook.Action mailAction = (Outlook.Action)Action;
> > // Get the current selection from the explorer and
> > // copy it to the FOLDER_NAME folder
> > switch (mailAction.Name)
> > {
> > case "Copy to " + FOLDER_NAME + " Folder":
> > Outlook.MailItem mailItem =
> > explorer.Selection[1] as Outlook.MailItem;
> > Outlook.MailItem mailItemCopy =
> > mailItem.Copy() as Outlook.MailItem;
> >
> > Outlook.MAPIFolder inbox =
> > this.GetNamespace("MAPI").GetDefaultFolder
> > (Outlook.OlDefaultFolders.olFolderInbox);
> > Outlook.MAPIFolder folder = null;
> >
> > // If the folder does not exist, Create it.
> > try
> > {
> > folder = inbox.Folders[FOLDER_NAME];
> > }
> > catch (System.Runtime.InteropServices.COMException)
> > {
> > // This exception is thrown when the folder is not found.
> > }
> > catch (Exception ex)
> > {
> > throw ex;
> > }
> > if (folder == null)
> > {
> > folder = inbox.Folders.Add(FOLDER_NAME,
> > Outlook.OlDefaultFolders.olFolderInbox);
> > }
> >
> > mailItemCopy.Move(folder);
> > // Do not display the inspector object.
> > Cancel = true;
> > break;
> > }
> > }
> > catch (Exception ex)
> > {
> > MessageBox.Show(ex.Message);
> > }
> > }
> >
> >
> >
> > "buechi" wrote:
> >
> > > I did some googling for creating a context menu entry IN VSTO 2005 Beta
> > > 2 (for example on a MailItem) with an icon and catching the click
> > > event? I didn't really find a promising solution. Has anyone a simple
> > > and clear example how to do this?
> > >
> > > Cheers,
> > >
> > > Daniel.
> > >
> > >
.
- References:
- VSTO 2005 Beta 2 Outlook Addin: How to create a context menu?
- From: buechi
- RE: VSTO 2005 Beta 2 Outlook Addin: How to create a context menu?
- From: Roosevelt Sheriff [MSFT]
- RE: VSTO 2005 Beta 2 Outlook Addin: How to create a context menu?
- From: David White [MSFT]
- VSTO 2005 Beta 2 Outlook Addin: How to create a context menu?
- Prev by Date: Re: Outlook Addin with Keyboard Shortcuts
- Next by Date: Visual Studio Cannot Find Microsoft Office 2003
- Previous by thread: RE: VSTO 2005 Beta 2 Outlook Addin: How to create a context menu?
- Next by thread: How to get list of all potential element's child elements.
- Index(es):
Relevant Pages
|