none
Hide "Upload" and "Upload all attachments" from ContextMenuAttachments RRS feed

  • Question

  • Hi!

    I am trying to hide these menus from the attachment context menu (for emails being edited).

    I use Ribbon and the XML I use is:

            public string GetCustomUI(string RibbonID)
            {
                if (RibbonID != "Microsoft.Outlook.Mail.Compose" && RibbonID != "Microsoft.Outlook.Explorer") return "";
                return
        @"<?xml version=""1.0"" encoding=""UTF-8""?>
    <customUI xmlns=""http://schemas.microsoft.com/office/2009/07/customui"" onLoad=""Ribbon_Load"" >
        <contextMenus>
            <contextMenu idMso=""ContextMenuAttachments"">
                <menu idMso=""SaveAttachToOneDrive"" getVisible=""RibbonGetVisible_SaveAttachToOneDrive"" />  
                <menu idMso=""UploadAttachmentToOneDrive"" getVisible=""RibbonGetVisible_UploadAttachmentToOneDrive"" />  
                <button
                    id=""MyContextMenuMailItem""
                    label=""Do something...""
                    onAction=""RibbonMenuClick""
                    getVisible=""RibbonGetVisible_CustomUI""
                    />
            </contextMenu> 
        </contextMenus>
    </customUI>
    ";
            }

    At this time RibbonGetVisible_SaveAttachToOneDrive and RibbonGetVisible_UploadAttachmentToOneDrive are just functions returning false (so they should never be visible). The MyContextMenuMailItem menu is here because I need it for other purposes.

    The problem is that the "Upload" menu is well hidden (UploadAttachmentToOneDrive) but the "Upload all attachments" is not. I am not sure if the ID SaveAttachToOneDrive belongs to "Upload all attachments" but from the documentation it seems so since it's a menu and it uses ContextMenuAttachments.

    the RibbonGetVisible_SaveAttachToOneDrive method is well called (so the menu is really shown) but for any reason that menu is not hidden.

    Any idea?

    Thanks

    Tuesday, August 28, 2018 6:04 PM

Answers

  • I finally found the problem. They menu is: UploadAllAttachmentsToCloud

    If I do this:

    <menu idMso=""UploadAllAttachmentsToCloud"" getVisible=""HideControl"" />  

    Then it Works. So it seems it is not documented. The same happens with the Cut menu... it is not listed and it is CutAttach. Why don't MS list all cases?? 

    • Marked as answer by pablo_1975 Wednesday, August 29, 2018 1:50 PM
    Wednesday, August 29, 2018 1:50 PM

All replies

  • Hi Pablo,

    Based on my test search, we can’t reproduce your question.

    Here is my test result: Button and menu can be displayed, but the idMso property of menu can’t display.



    There are some question I can’t not understand based on the information you’ve provided.

    To my understanding, The 'Upload all attachments' and "UploadAttachmentToOneDrive' can be hidden, but SaveAttachToOneDrive can't be hidden.

    According to my test, idMso which the value is SaveAttachToOneDrive, is not used under Menu.

    I have changed your code as follows:

    <menu id=""SaveAttachToOneDrive"" label=""test"" getVisible=""RibbonGetVisible_SaveAttachToOneDrive"" />  
    
    <menu id=""UploadAttachmentToOneDrive"" getVisible=""RibbonGetVisible_UploadAttachmentToOneDrive"" />  


    Could you take a screenshot to see your Message attachment page?

    Could you provide a reference where SaveAttachToOneDrive can hide the "Upload all attachments" menu?

    If possible, could you share your code, that will provide more info to help us resolve your problem.

    Hopefully the code above helps you.

    Please feel free to ask any questions. Looking forward to hearing from you.

    Best Regards,

    Bruce


    Wednesday, August 29, 2018 9:12 AM
    Moderator
  • Thanks Bruce. @Pablo Could you please confirm that Bruce' question?

    Wednesday, August 29, 2018 9:14 AM
    Moderator
  • Hi!

    I think the problem why you cannot reproduce is because you only have 1 attachment. In order for the "upload all" to appear you must have at least 2 attachments.

    My sources are here:

    This is the class I use for the IRibbonExtensibility:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Xml.Linq;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using Office = Microsoft.Office.Core;
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using System.Threading;
    using System.Collections;
    using System.Windows.Forms;
    using Microsoft.Office.Core;
    
    
    namespace CrackAddin
    {
    
        [ComVisible(true)]
        public class OutlookAddInExtensibility : IRibbonExtensibility
        {
            private IRibbonUI m_ribbon;
    
            public string GetCustomUI(string RibbonID)
            { 
                OutputDebugStringEx.Report("=======> CrackAddin: GetCustomUI("+RibbonID+")");
                if (RibbonID != "Microsoft.Outlook.Mail.Compose" && RibbonID != "Microsoft.Outlook.Explorer") return "";
                return
        @"<?xml version=""1.0"" encoding=""UTF-8""?>
    <customUI xmlns=""http://schemas.microsoft.com/office/2009/07/customui"" onLoad=""Ribbon_Load"" >
        <contextMenus> 
            <contextMenu idMso=""ContextMenuAttachments"">
                <menu idMso=""SaveAttachToOneDrive"" getVisible=""RibbonGetVisible_SaveAttachToOneDrive"" />   
                <menu idMso=""UploadAttachmentToOneDrive"" getVisible=""RibbonGetVisible_UploadAttachmentToOneDrive"" />   
                <button 
                    id=""MyContextMenuMailItem""
                    label=""A2C: Do something...""
                    onAction=""RibbonMenuClick""
                    getVisible=""RibbonGetVisible_CustomUI""
                    /> 
            </contextMenu>  
        </contextMenus>
    </customUI>
    ";
            }
    
            public string RibbonGetLabel( IRibbonControl control )
            {
                OutputDebugStringEx.Report("...RibbonGetLabel");
                return "My Control";
            }
    
            public void RibbonMenuClick(IRibbonControl control)
            {
                Microsoft.Office.Interop.Outlook.Selection selection = control.Context as Microsoft.Office.Interop.Outlook.Selection;
                List<Microsoft.Office.Interop.Outlook.Attachment> attachments = selection.OfType<Microsoft.Office.Interop.Outlook.Attachment>().ToList();
                foreach (Microsoft.Office.Interop.Outlook.Attachment att in attachments)
                {
                    OutputDebugStringEx.Report("=======> CrackAddin: Must do something in attachment " + att.DisplayName);
                }
                System.Diagnostics.Trace.WriteLine("MENU CHOSEN!!!");
            }
    
            public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                m_ribbon = ribbonUI;
                OutputDebugStringEx.Report("=======> CrackAddin: Ribbon_Load");
            }
    
            public void mySave(Office.IRibbonUI ribbonUI, ref bool bCancel)
            {
                OutputDebugStringEx.Report("=======> CrackAddin: mySave!!!");
            }
    
            public bool RibbonGetVisible_CustomUI( IRibbonControl control )
            {
                OutputDebugStringEx.Report("=======> CrackAddin: Invalidating ribbon...");
                m_ribbon.InvalidateControlMso("UploadAttachmentToOneDrive");
                m_ribbon.InvalidateControlMso("SaveAttachToOneDrive");
                return false;
            }
    
            public bool RibbonGetVisible_SaveAttachToOneDrive(IRibbonControl control)
            {
                OutputDebugStringEx.Report("=======> CrackAddin: RibbonGetVisible_SaveAttachToOneDrive");
                return false;
            }
    
            public bool RibbonGetVisible_UploadAttachmentToOneDrive(IRibbonControl control)
            {
                OutputDebugStringEx.Report("=======> CrackAddin: RibbonGetVisible_UploadAttachmentToOneDrive");
                Microsoft.Office.Interop.Outlook.Selection selection = control.Context as Microsoft.Office.Interop.Outlook.Selection;
                List<Microsoft.Office.Interop.Outlook.Attachment> attachments = selection.OfType<Microsoft.Office.Interop.Outlook.Attachment>().ToList();
                foreach (Microsoft.Office.Interop.Outlook.Attachment att in attachments)
                {
                    string szExtension = Path.GetExtension(att.DisplayName);
                    if (szExtension.ToUpper() == ".LIC")
                    {
                        OutputDebugStringEx.Report("=======> CrackAddin: Hiding " + att.DisplayName);
                        return false;
                    }
                    else OutputDebugStringEx.Report("=======> CrackAddin: Not Hiding " + att.DisplayName);
                }
                return true;
            }
    
        }
    }

    And this is the addin class itself:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using Office = Microsoft.Office.Core;
    using Microsoft.Office.Core;
    
    namespace CrackAddin
    {
        public partial class ThisAddIn
        {
            Outlook.Inspectors m_Inspectors = null;
            Outlook.Application m_app;
    
            protected override IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                return new OutlookAddInExtensibility();
            }
    
            /*********************************************************************/
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                try
                {
                    OutputDebugStringEx.Report("=======> CrackAddin: Starting");
                    m_app = this.Application;
                    m_Inspectors = Application.Inspectors;
                }
                catch (Exception exc)
                {
                    OutputDebugStringEx.Report("=======> CrackAddin: Exception in Startup: "+exc.ToString());
                }
            }
    
            /*********************************************************************/
            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
        }
    }
    

    As you see the goal is to prevent .lic files to be uploaded...

    What sounds strange is that the RibbonGetVisible_SaveAttachToOneDrive function is really called... if in the XML I change the MsoID to for example:

    <menu idMso=""BlaBlaBla"" getVisible=""RibbonGetVisible_SaveAttachToOneDrive"" />  

    then RibbonGetVisible_SaveAttachToOneDrive is not called... it smells like if the fact that this function is called means that this id is shown.

    I took it from a .xls provided by Microsoft. If you google SaveAttachToOneDrive then you will find this link:

    https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=2ahUKEwjkmKTwkpLdAhWJiZAKHSvrAqYQFjABegQIABAC&url=https%3A%2F%2Fwww.slipstick.com%2Ffiles%2FOutlook-command-controls-2016.xlsx&usg=AOvVaw0X9MiUMQhTO5BlfvHYTyjj

    and inside this link there is a section for the ContextMenuAttachments

    Thanks again

    Wednesday, August 29, 2018 11:30 AM
  • I finally found the problem. They menu is: UploadAllAttachmentsToCloud

    If I do this:

    <menu idMso=""UploadAllAttachmentsToCloud"" getVisible=""HideControl"" />  

    Then it Works. So it seems it is not documented. The same happens with the Cut menu... it is not listed and it is CutAttach. Why don't MS list all cases?? 

    • Marked as answer by pablo_1975 Wednesday, August 29, 2018 1:50 PM
    Wednesday, August 29, 2018 1:50 PM
  • Thank you for your feedback and sharing. As your mentioned, we will give feedback to the related team in time, and welcome you to our forum to ask questions.

    Thanks for your understanding.

    Best Regards,

    Simon


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Wednesday, August 29, 2018 2:23 PM
    Moderator
  • First of all - thank you! You literally saved me with this post... 

    Secondly, I'm curious- 

    How did you find this idMso if it's not documented? OutlookSpy or some such tool?

    Thanks! :)

    Uriel

    Sunday, September 8, 2019 12:17 PM