c# - 用C#读取outlook MSG文件中的书签

标签 c# outlook vsto bookmarks msg

我的目标是以某种方式能够读取 outlook .msg 文件中的书签,然后用不同的文本替换它们。我想用 C# 来做到这一点。

我知道如何访问正文和更改文本,但想知道是否有办法直接访问所有书签的列表及其位置,以便我可以轻松替换它们,而不是浏览整个正文,将其拆分等等......

编辑:this is how a bookmark window looks like可以从该窗口分配书签,但应该可以通过 C# 获取该列表。

enter image description here

如有任何相关信息,我们将不胜感激。 提前致谢。

最佳答案

自展望most often uses Word as it's body editor - 您需要添加对 Microsoft.Office.Interop.Word.dll 的项目引用,然后访问 Outlook Inspector 的 WordEditorInspector.Activate期间事件。一旦您有权访问 Word.Document - 这对 load up the Bookmarks 来说是微不足道的并访问/修改它们的值。

Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
((Outlook.InspectorEvents_10_Event)inspector).Activate += () =>
{   // validation to ensure we are using Word Editor
    if (inspector.EditorType == Outlook.OlEditorType.olEditorWord && inspector.IsWordMail())
    {
        Word.Document wordDoc = inspector.WordEditor as Word.Document;
        if (wordDoc != null)
        {
            var bookmarks = wordDoc.Bookmarks;
            foreach (Word.Bookmark item in bookmarks)
            {
                string name = item.Name; // bookmark name
                Word.Range bookmarkRange = item.Range; // bookmark range
                string bookmarkText = bookmarkRange.Text; // bookmark text
                item.Select(); // triggers bookmark selection
            }
        }
    }
};

关于c# - 用C#读取outlook MSG文件中的书签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16559739/

相关文章:

c# - 无法正确加载底层压缩例程

c# - 确定所选电子邮件是来自收件箱还是已发送邮件

interop - Microsoft Outlook Interop(提取附件)非常慢

c# - Office365 API : OAuth2 AccessTokens for app-only require that the

msbuild - 构建错误 + 为 excel 2010 创建 VSTO 插件

excel - 如何检测工作表上的过滤器是否更改?

c# - ASP.NET Core 2.0 认证中间件

c# - 在 Windows 服务中使用 Rx

c# - 从另一个应用程序中运行的 FarPoint Spread 控件获取数据

c# - Word 命令行参数空间问题