检查 Outlook 任务列表项是否已存在
Check to see if an Outlook TaskList Item already exists
我想以编程方式从 SQL 数据库中获取新任务并将它们添加到我的 Outlook 任务列表中。我查询我需要的所有数据并将它们添加到 MS-Outlook 中的任务列表中是没有问题的。下面是我的代码:
Outlook.TaskItem oTask = outlookApp.CreateItem(Outlook.OlItemType.olTaskItem);
oTask.Subject = "Go do task 1";
oTask.DueDate = Convert.ToDateTime("03/20/2015");
oTask.StartDate = Convert.ToDateTime("03/20/2015");
oTask.Body = "test task body";
oTask.SchedulePlusPriority = "High";
oTask.Status = Microsoft.Office.Interop.Outlook.OlTaskStatus.olTaskInProgress;
oTask.Save();
但是,我想检查 Outlook 任务列表中是否已经存在相同的项目(1 或 2 列的组合)。如果任务项已经存在,则不要保存它。有什么办法吗?
非常感谢任何帮助。
标准是什么?打开您创建任务的文件夹 (Application.Session.GetDefaultFolder(olFolderTasks),然后使用项目进行搜索。Find/FindNext/Restrict
这个有用吗? (源代码已修改,感谢 Dmitry)
private bool IsTaskItemExists(TaskObject oTaskItem)
{
Outlook.NameSpace ns = null;
Outlook.MAPIFolder tasksFolder = null;
Outlook.Items taskFolderItems = null;
Outlook.TaskItem task = null;
Outlook.Application outlookApp = new Application();
bool foundItem = false;
try
{
ns = outlookApp.Session;
tasksFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
taskFolderItems = tasksFolder.Items;
foundItem = (taskFolderItems.Find(String.Format("[Property Name]='{0}'", oTaskItem.Property) ) != null);
return foundItem;
}
finally
{
if (taskFolderItems != null)
Marshal.ReleaseComObject(taskFolderItems);
if (tasksFolder != null)
Marshal.ReleaseComObject(tasksFolder);
if (ns != null)
Marshal.ReleaseComObject(ns);
}
}
我想以编程方式从 SQL 数据库中获取新任务并将它们添加到我的 Outlook 任务列表中。我查询我需要的所有数据并将它们添加到 MS-Outlook 中的任务列表中是没有问题的。下面是我的代码:
Outlook.TaskItem oTask = outlookApp.CreateItem(Outlook.OlItemType.olTaskItem);
oTask.Subject = "Go do task 1";
oTask.DueDate = Convert.ToDateTime("03/20/2015");
oTask.StartDate = Convert.ToDateTime("03/20/2015");
oTask.Body = "test task body";
oTask.SchedulePlusPriority = "High";
oTask.Status = Microsoft.Office.Interop.Outlook.OlTaskStatus.olTaskInProgress;
oTask.Save();
但是,我想检查 Outlook 任务列表中是否已经存在相同的项目(1 或 2 列的组合)。如果任务项已经存在,则不要保存它。有什么办法吗?
非常感谢任何帮助。
标准是什么?打开您创建任务的文件夹 (Application.Session.GetDefaultFolder(olFolderTasks),然后使用项目进行搜索。Find/FindNext/Restrict
这个有用吗? (源代码已修改,感谢 Dmitry)
private bool IsTaskItemExists(TaskObject oTaskItem)
{
Outlook.NameSpace ns = null;
Outlook.MAPIFolder tasksFolder = null;
Outlook.Items taskFolderItems = null;
Outlook.TaskItem task = null;
Outlook.Application outlookApp = new Application();
bool foundItem = false;
try
{
ns = outlookApp.Session;
tasksFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
taskFolderItems = tasksFolder.Items;
foundItem = (taskFolderItems.Find(String.Format("[Property Name]='{0}'", oTaskItem.Property) ) != null);
return foundItem;
}
finally
{
if (taskFolderItems != null)
Marshal.ReleaseComObject(taskFolderItems);
if (tasksFolder != null)
Marshal.ReleaseComObject(tasksFolder);
if (ns != null)
Marshal.ReleaseComObject(ns);
}
}