Outlook插件使用用户控件(任务窗格/自定义窗体)(译文)
By S.F.
本文链接 https://www.kyfws.com/news/outlook-addon-with-user-control-task-pane-custom-f/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 7 分钟阅读 - 3247 个词 阅读量 0Outlook插件使用用户控件(任务窗格/自定义窗体)(译文)
原文地址:https://www.codeproject.com/Tips/5281978/Outlook-AddOn-With-User-Control-Task-Pane-Custom-F
原文作者:Leo Chapiro
译文由本站翻译
前言
Outlook AddOn to store the attachments in the file system Outlook插件将附件存储在文件系统中 Outlook AddOn (VSTO) to store the attachments in the file system This AddOn will be shown as a Pane integrated in Outlook, so the user is able simple to drag-drop the Email into the appropriate folder. The folder will be automatically selected based on the current Email address. Outlook AddOn(VSTO)将附件存储在文件系统中此插件将显示为集成在Outlook中的窗格,因此用户可以轻松地将Email拖放到适当的文件夹中.该文件夹将根据当前的电子邮件地址自动选择.
- Download OutlookAddOn.zip - 194.9 KB下载OutlookAddOn.zip-194.9 KB
- Download AddOn_only.zip - 72.2 KB下载AddOn_only.zip-72.2 KB
Introduction(介绍)
The goal of this project is to show how simply is it, to create a custom pane in the Microsoft Outlook [3] and do some action based on the Email address of the current Email object:
这个项目的目的是展示它的简单性,在Microsoft Outlook [3]中创建一个自定义窗格,并根据当前Email对象的Email地址执行一些操作:
This tool reads an address of current selected Email and shows in the pane on the right side the appropriate folders with its sub-folders.
该工具读取当前所选电子邮件的地址,并在右侧窗格中显示相应的文件夹及其子文件夹.
Now user can easy drag-drop the Email in one of the sub-folder in order to save its attachment there.
现在,用户可以轻松地将电子邮件拖放到子文件夹之一中,以将其附件保存在那里.
The mapping between the Email addresses and the folders take place in the configuration file, please take a look at OutlookAddOn.xml:
电子邮件地址和文件夹之间的映射在配置文件中进行,请查看OutlookAddOn.xml:
<file_system> impressum@amazon.de|C:\TEMP rechnungsstelle@1und1.de|D:_Download </file_system>
<文件系统> impressum@amazon.de | C:\ TEMP rechnungsstelle@1und1.de|D:\ _下载 </file_system>
As you see, the address is separated from folder by pipe character like this:
如您所见,地址通过文件夹字符与文件夹分开,如下所示:
Attachment_of_Emails_with_this_address … | … should_be_saved_in_sub-folders_of_this_folder
<文件夹>带有此地址的电子邮件附件… | … should_be_saved_in_sub-folders_of_this_folder
As the is a list of enries, user is able to add as much as addresses as he need.
由于是条目列表,因此用户可以根据需要添加尽可能多的地址.
Background(背景)
The technique behind is the VSTO (Visual Studio Tools For Office), this API make it possible to get all informations of a Email object, for example the count of attachments as well as the attachment itself.
背后的技术是VSTO(用于Office的Visual Studio工具),此API使得获取电子邮件对象的所有信息成为可能,例如附件的数量以及附件本身.
Some registry entries are necessary when you deploy VSTO Add-ins that are created by using Visual Studio. These registry entries provide information that enables the Microsoft Office application to discover and load the VSTO Add-in [1].
当您部署使用Visual Studio创建的VSTO加载项时,某些注册表项是必需的.这些注册表项提供的信息使Microsoft Office应用程序能够发现和加载VSTO加载项[1].
When a VSTO Add-in is installed, it can be registered in two ways:
安装VSTO加载项后,可以通过两种方式进行注册:
- *For the current user only (that is, it is available only to the user that is logged on to the computer when the VSTO Add-in is installed). In this case, the registry entries are created under the HKEY_CURRENT_USER.*仅对于当前用户(即,它仅对安装VSTO加载项时登录到计算机的用户可用).在这种情况下,注册表项是在HKEY_CURRENT_USER下创建的.
- *For all users (that is, any user that logs on to the computer can use the VSTO Add-in). In this case, the registry entries are created under HKEY_LOCAL_MACHINE.*对于所有用户(即,任何登录到计算机的用户都可以使用VSTO加载项).在这种情况下,注册表项是在HKEY_LOCAL_MACHINE下创建的.
This is an example of how to install Add-in for current user:
这是一个如何为当前用户安装外接程序的示例:
Windows Registry Editor Version 5.00
Windows注册表编辑器版本5.00
[HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\Addins\OutlookAddOn] “Description”=“OutlookAddOn” “FriendlyName”=“OutlookAddOn” “LoadBehavior”=dword:00000003 “Manifest”=“H:/_Projekte/OutlookAddOn/bin/Release/OutlookAddOn.vsto|vstolocal”
[HKEY_CURRENT_USER \ Software \ Microsoft \ Office \ Outlook \ Addins \ OutlookAddOn] “说明” =" OutlookAddOn" " FriendlyName" =" OutlookAddOn" " LoadBehavior" =dword:00000003 “清单” =" H:/_ Projekte/OutlookAddOn/bin/Release/OutlookAddOn.vsto | vstolocal"
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Vsto Runtime Setup\v4] “EnableVSTOLocalUNC”=dword:00000001
[HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Vsto Runtime Setup \ v4] " EnableVSTOLocalUNC" =dword:00000001
*You will need to replace the H:/_Projekte/OutlookAddOn/bin/Release/ with the path of the folder contained AddOn and to save this code snipped in a file .reg. By executing this file (double click) all keys will be added to the windows registry:
您将需要将H:/_ Projekte/OutlookAddOn/bin/Release/替换为包含AddOn的文件夹的路径,并将此代码保存在* .reg文件中.通过执行此文件(双击),所有键都将添加到Windows注册表中:
How Outlook VSTO AddOn Works (Callbacks)(Outlook VSTO附加组件如何工作(回调))
There are two important callback function that are necessarily needed to get an AddOn working [4]:
要使AddOn正常工作,必须具备两个重要的回调函数:[4]:
The
Startup
method - a kind of constructor, a perfect place to create our custom form / pane:
Startup方法-一种构造函数,是创建自定义表单/窗格的理想场所:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
try
{
oUserCtrl = new axUserCtrl(this);
...
And the
Explorer.SelectionChange
event which will be fired every time when an Email item get selected:
还有ʻExplorer.SelectionChange`事件,该事件将在每次选择电子邮件项时触发:
private void CurrentExplorer_Event()
{
if (this.Application.ActiveExplorer().Selection.Count == 1)
{
Object selObject = Application.ActiveExplorer().Selection[1];
if (selObject is MailItem)
{
MailItem mailItem = (selObject as MailItem);
oUserCtrl.SetEmail(mailItem);
...
That is actually all that we need:
实际上,这就是我们所需要的:
- We have created a custom form that will be shown as a pane embetted in Outlook and我们创建了一个自定义表单,该表单将显示为在Outlook和
- *We get a notification / callback every time the Email selection changed - the current Email item will be provided to the custom form!*每当电子邮件选择更改时,我们都会收到通知/回调-当前的电子邮件项目将提供给自定义表单!
One of the infotmation that we need is the Email address to show an appropriated folder, the second information is the path to the attachment to store it into this folder.
我们需要的信息之一是显示适当文件夹的电子邮件地址,第二信息是将其存储到此文件夹的附件的路径.
Another important point is to use the worker thraed wherever we do something in the background:
另一个重要的一点是,无论我们在后台执行什么操作,都应使用工作线程:
_workerThread = new Thread(_oWorker.GetResultList);
_workerThread.Start();
We should avoid the freezing of the GUI, otherwise our AddIn can be refused by Outlook.
我们应该避免冻结GUI,否则Outlook可能会拒绝我们的AddIn.
Using the code(使用代码)
The
axFileSystemWorker
is derrived fromaxBaseWorker
in order to show one of many possibilities, what can be achieved by using the VSTO interface:
" axFileSystemWorker"是从" caseWorker"派生的,目的是展示多种可能性之一,这可以通过使用VSTO接口来实现:
enMode nMode = _oWorker.GetMode();
if (nMode == enMode.eFILE_SYSTEM)
_oWorker = new axFileSystemWorker(this) as iWorker;
/*
else if () ... and so long to use another modes
*/
We can easily implement a REST interface (POST, GET) or something else by derriving from
axBaseWorker
and overriding the virtual methods, for example:
我们可以通过从" axBaseWorker"派生并覆盖虚拟方法来轻松实现REST接口(POST,GET)或其他方法,例如:
public virtual bool Connect()
{
throw new NotImplementedException();
}
Points of Interest(兴趣点)
[1] Registry entries for VSTO Add-ins - https://docs.microsoft.com/en-us/visualstudio/vsto/registry-entries-for-vsto-add-ins?view=vs-2019
[1] VSTO加载项的注册表项-[https://docs.microsoft.com/zh-cn/visualstudio/vsto/registry-entries-for-vsto-add-ins?view=vs-2019](https ://docs.microsoft.com/zh-CN/visualstudio/vsto/registry-entries-for-vsto-add-ins?view =vs-2019)
[2] Create VSTO Add-ins for Office by using Visual Studio - https://docs.microsoft.com/en-us/visualstudio/vsto/create-vsto-add-ins-for-office-by-using-visual-studio?view=vs-2019
[2]使用Visual Studio创建Office的VSTO加载项-[https://docs.microsoft.com/zh-cn/visualstudio/vsto/create-vsto-add-ins-for-office-by-using- visual-studio?view =vs-2019](https://docs.microsoft.com/zh-cn/visualstudio/vsto/create-vsto-add-ins-for-office-by-using-visual-studio?view =vs-2019)
[3] Add a custom task pane to an application - https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-add-a-custom-task-pane-to-an-application?view=vs-2019
[3]将自定义任务窗格添加到应用程序-[https://docs.microsoft.com/zh-cn/visualstudio/vsto/how-to-add-a-custom-task-pane-to-an-application ?view =vs-2019](https://docs.microsoft.com/zh-cn/visualstudio/vsto/how-to-add-a-custom-task-pane-to-an-application?view=vs- 2019)
[4] Programmatically determine the current Outlook item - https://docs.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-determine-the-current-outlook-item?view=vs-2019
[4]以编程方式确定当前Outlook项-https://docs.microsoft.com/zh-cn/visualstudio/vsto/how-to-programmatically-determine-the-current-outlook-item?view=vs-2019
History(历史)
Version 1.1.0 - the current version of tool.
版本1.1.0-工具的当前版本.
Added chapter “How Outlook VSTO AddOn Works”
添加了" Outlook VSTO加载项的工作原理"一章
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# .NET Visual-Studio Intermediate VSTO Outlook AddIn DevOps 新闻 翻译