outlook - 在 Outlook C# 中使用比较运算符创建自定义字段过滤器
问题描述
我创建了一个过滤器,它将比较自定义用户属性的值并仅显示满足要求的电子邮件。
过滤器在我有=
比较值时起作用,但在我有运算符时不起作用<=
。
下面是我的过滤器。这行得通。
string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" = '60'";
Outlook.Items restrictedMails = selectedFolder.Items.Restrict(filter);
这行不通。
string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" <= '60'";
Outlook.Items restrictedMails = selectedFolder.Items.Restrict(filter);
在自定义文件中保存值的代码如下。
int duration = (int)completed.Subtract(received).TotalMinutes;
try
{
MailUserProperties = SelectedMail.UserProperties;
MailUserProperty = MailUserProperties.Add("TimeSpent", Outlook.OlUserPropertyType.olText, true, 1);
MailUserProperty.Value = duration;
SelectedMail.Save();
}
任何人都可以在这里帮助如何让过滤器工作吗?
提前致谢。
解决方案
string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" = '60'";
这里60
不是数字,而是字符串。所以,基本上,比较两个字符串。
MailUserProperty = MailUserProperties.Add("TimeSpent", Outlook.OlUserPropertyType.olText, true, 1);
您添加一个字符串用户属性,然后想要应用一个比较器。只有整数值才有意义。因此,代码应如下所示:
MailUserProperty = MailUserProperties.Add("TimeSpent", Outlook.OlUserPropertyType.olInteger, true, 1);
只有这样,您才能尝试使用以下过滤器:
string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" <= 60";
推荐阅读
- java - 服务器应用程序挂起 Java socket 编程
- html - 如何去除按钮的底部空间?
- android - Ionic 3 对生产是否可靠?
- javascript - polymer-webpack-loader:如何导入和转译 Polymer .html 模板
- unity3d - 无法将拍摄的照片保存在 hololens 应用程序中
- php - 如何在 CodeIgniter 中生成自定义 ID?
- visual-studio - 如何使用不可复制不可移动类的对象成员函数启动线程?
- html - 在不加载 HTML 的情况下绑定 Angularjs 指令(bootstrap .modal('show'))
- javascript - 将数组转换为对象并将对象推入数组-javascript
- c# - WriteClientCharacteristicConfigurationDescriptorAsync 在 UWP 中不起作用