How to get the current selected MailItem, TaskItem or AppointmentItem in C#, when contextmenu item is clicked in Microsoft Outlook 2010

If you use a contextmenu in you’re Microsoft Outlook 2010 C# add-in and want to use the item the user clicked on, you should use the first object in the

Globals.ThisAddIn.Application.ActiveExplorer().Selection

image

 

Note

The Selection collection does not start at index 0 but index 1, if you use Selection[0] an index out of bounds exception will occur.

 

ContextMenu.xml

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
    <contextMenus>
        <contextMenu idMso="ContextMenuFolder">
            <button idMso="FolderPropertiesContext" getVisible="IsVisible" />
            
        </contextMenu>
        <contextMenu idMso="ContextMenuMailItem">
            <button id="MyContextMenuMailItem"
            label="Start Timer"
            onAction="OnMyButtonClick"/>
        </contextMenu>
        <contextMenu idMso="ContextMenuTaskItem">
            <button id="MyContextMenuTaskItem"
                    label="Start Timer"
                    onAction="OnMyButtonClick"/>
        </contextMenu>
        <contextMenu idMso="ContextMenuCalendarItem">
            <button id="MyContextMenuCalendarItem"
          label="Start Timer"
          onAction="OnMyButtonClick"/>
        </contextMenu>
    </contextMenus>
</customUI>

 

ContextMenu.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Ada.Tip.WpfUserControls.BC;

namespace Ada.Tip.OutlookAddIn
{
    [ComVisible(true)]
    public class ContextMenuRibbon : Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;

        public ContextMenuRibbon()
        {
        }        
        public bool IsVisible(Office.IRibbonControl control)
        {
            //string foldername = ((Microsoft.Office.Interop.Outlook.Folder)control.Context).Name;
            //if (foldername == "Inbox")
            //{
            //  return false;
            //}
            return true;
        }
        #region IRibbonExtensibility Members

        public string GetCustomUI(string ribbonID)
        {
            return GetResourceText("Ada.Tip.OutlookAddIn.contextMenuRibbon.xml");
        }

        #endregion

        #region Ribbon Callbacks
        //Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
        public void Ribbon_Load(Office.IRibbonUI ribbonUI)
        {
            this.ribbon = ribbonUI;
            Globals.ThisAddIn.RibbonUI = ribbonUI;
        }
        /// <summary>
        /// Event fires when user clicks in the ContextMenu on "Start Timer"
        /// </summary>
        /// <param name="control"></param>
        public void OnMyButtonClick(Office.IRibbonControl control)
        {
            Globals.ThisAddIn.dashboardUserControl.dashboard.StopCurrentWorkItem();

            // Determine subject of selected item
            string subject = string.Empty;
            Explorer explorer = Globals.ThisAddIn.app.ActiveExplorer();
            if (explorer != null && explorer.Selection != null && explorer.Selection.Count > 0)
            {
                object item = explorer.Selection[1];
                if (item is MailItem)
                {
                    MailItem mailItem = item as MailItem;
                    subject = mailItem.Subject;
                }
                if (item is TaskItem)
                {
                    TaskItem taskItem = item as TaskItem;
                    subject = taskItem.Subject;
                }
                if (item is AppointmentItem)
                {
                    AppointmentItem appointmentItem = item as AppointmentItem;
                    subject = appointmentItem.Subject;
                }
            }

            
        }
        #endregion

        #region Helpers
        
        private static string GetResourceText(string resourceName)
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            string[] resourceNames = asm.GetManifestResourceNames();
            for (int i = 0; i < resourceNames.Length; ++i)
            {
                if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
                {
                    using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                    {
                        if (resourceReader != null)
                        {
                            return resourceReader.ReadToEnd();
                        }
                    }
                }
            }
            return null;
        }

        #endregion
    }
}

How to show more appointments in the To-Do Bar of Microsoft Outlook 2010

If you wanted to view more appointments in the To-Do Bar of Microsoft Outlook 2007, you could change the default of 3 by right clicking on the To-Do Bar > Views > To-Do Bar > Options > Show Appointments > Number of appointments.

http://blogs.msdn.com/outlook/archive/2008/01/25/make-the-to-do-bar-work-for-you.aspx

 

 

 

 

This option is removed in Microsoft Outlook 2010:

image

 

To show more appointments in the To-Do Bar just increase the viewed space by dragging the divider bar:

image

In cooperation with Marc Valk

Sync problem with Windows 2008 RC2 or Windows 7 x64 and Microsoft Outlook 2010 with Windows Mobile 6.5 resolved

If you have problems synchronising you’re Windows Mobile 6.5 on Windows 2008 RC2 and Microsoft Outlook 2010 with the message “Outlook is not the default email client”, you can set Microsoft Outlook 2010 as default email client in Microsoft Outlook 2010:

File > Options:

image

Check “Make Outlook the default program for E-Mail, Contacts, and Calendar and ”Click on “Default Programs”

image

Check the Select all checkbox.

Install Windows Mobile device centre 6.1 (Microsoft Windows Mobile Device Center 6.1 Driver for Windows Vista (64-bit).exe). Sync you’re Windows Mobile 6.5 and uncheck the One Notes sync

This worked for me, I am know syncing my HD2 Windows Mobile 6.5 phone with Microsoft Outlook 2010 on a Windows 2008 RC2 x64 server.

Short cut for pasting unformatted text, with the default paste options in Microsoft Office 2010

In most cases when I copy text from a source document or website and want to paste this text in Microsoft Office Outlook or Microsoft Office Word, I want the text to be formatted like the destination document (pasting as unformatted text). Previously I used two methods to accomplish this:

  • Paste > Paste Special > Unformatted Text > OK ( 4 clicks)
  • Notepad ctrl+a then ctrl+v the ctrl+a and then ctrl+c (1 click but many key presses)

Paste special dialog

image

In Microsoft Office 2010 (and perhaps in older Microsoft Office versions) you can now set default paste options to unformatted text. The pasted text will be formatted like the destination document

In Microsoft Office Word 2010

  • File > Options > Advanced > [Cut, copy and paste] section > Keep Text Only

image

In Microsoft Office Outlook 2010

  • Open a new mail message
  • File > Options > Mail > Editor Options > Advanced > [Cut, copy and paste] section > Keep Text Only

image

When you paste text in you’re mail or word document, it will be formatted like the mail or document.

 

Microsoft Office 2010 OneNote

  • In Microsoft Office 2010 OneNote, you can use the [Contenxt Menu Key] + T, instead of [CTRL + V] to paste unformatted text.
  • Or use alt + h + v + t

Microsoft Outlook 2007 Search

General
· Search is not case-sensitive.
· Search for “All Mail Items”, includes all outlook files and includes folders like Inbox, Outbox, Sent Items and Conversation History

If you want to search for a Text “test”:

subject: "test " OR contents:"test " OR attachment:"test "

If you want to search for a Person "Roel van Lisdonk", you could enter only the first name with a space:

from:"roel " OR cc:"roel " OR bcc:"roel " OR to:"roel " OR subject:"roel " OR contents:"roel " OR attachment:"roel "

Microsoft Outlook 2007 How to group by date and not date and time

If you want to search all mail items (Inbox and Sent Items) in Microsoft Outlook 2007 for the text: “test” and group by received date and not date and time:

Click in the Menu on Go > Mail :

image

Click on “All Mail Items”

Click in the Menu on View > Current View > Customize Current View… > Other Settings
image

Check the “Show items in Groups
image

This will group by date and not date and time, the group by box contains a field: Date
image
This will group by: Yesterday, then all days of the current week, then last week, then all weeks of current month, the last month, then older

Donwload pictures automatically in HTML e-mail messages or RSS items in Microsoft Outlook 2007

If you want to allow Microsoft Outlook 2007, to download pictures in HTML e-mail messages automatically, follow these steps:
1. Start Microsoft Outlook 2007
2. On the Tools menu, click Trust Center…
3. Click to clear the “Don’t download pictures automatically in HTML e-mail messages or RSS items” checkbox

image

This wil prevent the message:

image