Filter Outlook appointments by category

谁说我不能喝 提交于 2019-12-12 11:16:29

问题


I have written this code to find the total duration of all appointments of a specified category within a specified time range:

private readonly MAPIFolder _timing;

private int CalculateTotalDuration(DateTime start, DateTime end, string category)
{
    string filter = String.Format(
        "([Start] >= '{0:g}') AND ([End] <= '{1:g}') AND ([Categories] = '{2}')",
        start, end, category);
    return _timing.Items.Restrict(filter).Cast<AppointmentItem>().
        Sum(appt => appt.Duration);
}

This code results in the following exception when used with Russian version of Outlook (I did not test it with English version though):

System.Runtime.InteropServices.COMException was unhandled
  Message=Условие неверно.
  Source=Microsoft Outlook
  ErrorCode=-2147352567
  StackTrace:
       at Microsoft.Office.Interop.Outlook._Items.Restrict(String Filter)
       ...

When I replace [Categories] with [Категории], i.e.

string filter = String.Format(
    "([Start] >= '{0:g}') AND ([End] <= '{1:g}') AND ([Категории] = '{2}')",
    start, end, category);

it works with Russian version of Outlook. But obviously it will not work with other languages.

How to filter Outlook appointments by category in a multilanguage way?


回答1:


Try to use a SQL query (prefix the query with "@SQL=") and use the DASL name for the Categories - http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/Keywords/0x0000101F or urn:schemas:mailheader:keywords.




回答2:


I have come up with the following DASL filter that works for me:

var filter = String.Format(
    "@SQL=(\"urn:schemas:calendar:dtstart\" >= '{0:g}' " +
    "AND \"urn:schemas:calendar:dtend\" <= '{1:g}' " +
    "AND \"urn:schemas-microsoft-com:office:office#Keywords\" LIKE '%{2}%')",
    start, end, category);

Actually I have built it using the DASL query builder:

To display a Query Builder tab I have created QueryBuilder key in HKEY_CURRENT_USER\Software \Microsoft\Office\14.0\Outlook as described here.

Thanks to Dmitry who suggested to use DASL.



来源:https://stackoverflow.com/questions/14133471/filter-outlook-appointments-by-category

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!