简体   繁体   English

VSTO Outlook 插件 - If 语句 / CurrentUser

[英]VSTO Outlook Plugin - If Statement / CurrentUser

Is it possible to include an If statement in a VSTO plugin that will offer up different Context Menu items based on the Current User's attributes, eg Department?是否可以在 VSTO 插件中包含一个 If 语句,它将根据当前用户的属性(例如部门)提供不同的上下文菜单项?

I am attempting to use the documentation in here https://docs.microsoft.com/en-us/office/client-developer/outlook/pia/how-to-get-information-about-the-current-user to add to my existing code:我正在尝试使用此处的文档https://docs.microsoft.com/en-us/office/client-developer/outlook/pia/how-to-get-information-about-the-current-user添加到我现有的代码:

 <contextMenu idMso="ContextMenuMailItem"> <menu id="ReplyListContext" label="Choose a Quick Reply" insertBeforeMso="Copy"> <button id="CharityContext" label="Charity Request" onAction="Charity_Click"/> > </menu> </contextMenu>

 public void Charity_Click(Office.IRibbonControl control) { Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer(); if (explorer.= null) { Outlook.Selection selection = explorer;Selection. if (selection.Count >= 1) { Outlook.MailItem mailItem = selection[1] as Outlook;MailItem. if (mailItem.= null) //could be something other than MailItem { Outlook;MailItem response = mailItem.ReplyAll(). response.BodyFormat = Outlook;OlBodyFormat.olFormatHTML. response;HTMLBody = "<p>Thanks for your e-mail</p><p>text text text</p><p>Many thanks</p> " + response.HTMLBody; response.Send(); } } } }

I have a number of these responses and want different departments to be presented with different options when they open Outlook我有很多这样的回应,并希望在打开 Outlook 时向不同的部门提供不同的选项

You could use DynamicMenu你可以使用DynamicMenu

  1. In your ribbonXML, add a dynamicmenu item:在您的dynamicmenu中,添加一个动态菜单项:

     <contextMenus> <contextMenu idMso='ContextMenuCell'> <dynamicMenu id='dynamicRoot' label='Sample Dynamic' getContent='GetMenuCustomContent' /> </contextMenu> </contextMenus>
  2. Your callback function GetMenuCustomContent will be called whenever the hosting app ( Outlook ) needs to build the menu.每当托管应用程序 ( Outlook ) 需要构建菜单时,都会调用您的回调 function GetMenuCustomContent

  3. Return different XML according to the CurrentUser.根据CurrentUser返回不同的XML。

     public string GetMenuCustomContent(IRibbonControl control) { // here get the current user and return different XML // accodring to any condition if(SomeOtherCondition) { return @"<menu xmlns='http://schemas.microsoft.com/office/2009/07/customui'> <button id='some_button' label='UserType1' onAction='DoSomething'/> </menu>"; } else if (SomeOtherCondition) { return @"<menu xmlns='http://schemas.microsoft.com/office/2009/07/customui'> <button id='some_button2' label='UserType2' onAction='DoSomething2'/> </menu>"; } return ""; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM