haw*_*bsl 12 outlook office-interop
似乎没有太多信息或任何良好的代码示例用于以编程方式设置Outlook 2007 MailItem的类别.
MSDN有一个有限的页面,并提到使用VB的Split函数,或多或少说" 你自己从这里开始,所以你自己解决 ".
据我所知,我们将类别操作为mailitem的逗号分隔字符串属性.它似乎有点原始,是不是都有它呢?
是否每个人都只是挖掘出自己的字符串函数库,并解析类别属性,相信没有一个懵懵懂懂地得到当多个类别单个的MailItem设置和(但愿)类别更名?
Sli*_*SFT 22
您可以选择以任何方式操作逗号分隔的字符串.要插入一个类别,我通常会检查当前字符串是否为空,然后只是分配它.如果类别不为null,那么如果它尚不存在则附加它.要删除项目,我只需用空字符串替换类别名称.
var customCat = "Custom Category";
if (mailItem.Categories == null) // no current categories assigned
mailItem.Categories = customCat;
else if (!mailItem.Categories.Contains(customCat)) // insert as first assigned category
mailItem.Categories = string.Format("{0}, {1}", customCat, mailItem.Categories);
Run Code Online (Sandbox Code Playgroud)
var customCat = "Custom Category";
if (mailItem.Categories.Contains(customCat))
mailItem.Categories = mailItem.Categories.Replace(string.Format("{0}, ", customCat), "").Replace(string.Format("{0}", customCat), "");
Run Code Online (Sandbox Code Playgroud)
有很多种方法可以操作字符串 - 他们只是选择保持序列化数据结构简单.
我倾向于在加载项启动期间创建自己的类别以验证它们是否存在.当然 - 类别重命名是一个问题,但如果您确保每次加载项加载时您的类别都存在,您至少可以确保某种程度的有效性.
var customCat = "Custom Category";
if (Application.Session.Categories[customCat] == null)
Application.Session.Categories.Add(customCat, Outlook.OlCategoryColor.olCategoryColorDarkRed);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8017 次 |
| 最近记录: |