c# - 如何以编程方式将任务添加到特定的 Outlook 存储
问题描述
我有一段代码可以获取特定商店的任务。
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace ns = app.Session;
Outlook.Stores stores = ns.Stores;
try
{
foreach (Outlook.Store store in stores)
{
if (store.DisplayName == comboBoxAccounts.Text)
{
Outlook.MAPIFolder tasksFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
foreach (Outlook.TaskItem task in tasksFolder.Items)
{
if (task.Subject == comboBoxContacts.Text)
{
comboBoxProperties.Items.Add(task.Body);
}
}
if (tasksFolder != null)
Marshal.ReleaseComObject(tasksFolder);
}
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
statusLabel.Text = ex.ToString();
}
finally
{
if (ns != null)
Marshal.ReleaseComObject(ns);
}
我正在尝试将等价物放在一起以将任务添加到特定商店。下面的代码将任务添加到 Outlook 中的主帐户,但我想使用另一个帐户。
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace ns = app.Session;
try
{
Outlook.TaskItem task = app.CreateItem(Outlook.OlItemType.olTaskItem);
task.Subject = strContact;
task.StartDate = DateTime.Now;
task.DueDate = DateTime.Now.AddDays(2);
task.Status = Outlook.OlTaskStatus.olTaskNotStarted;
task.Body = xDoc.ToString();
task.Save();
}
finally
{
}
我该如何做类似于 store.CreateItem() 的事情?
谢谢
更新:解决方案
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace ns = app.Session;
Outlook.Stores stores = ns.Stores;
try
{
foreach (Outlook.Store store in stores)
{
if (store.DisplayName == strAccount)
{
Outlook.MAPIFolder tasksFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
Outlook.TaskItem task = (Outlook.TaskItem)tasksFolder.Items.Add(Outlook.OlItemType.olTaskItem);
task.Subject = strContact;
task.StartDate = DateTime.Now;
task.DueDate = DateTime.Now.AddDays(2);
task.Status = Outlook.OlTaskStatus.olTaskNotStarted;
task.Body = xDoc.ToString();
task.Save();
}
}
}
finally
{
}
解决方案
不要使用Application.CreateItem
. 从Application.Session.Stores
集合中检索商店,调用Store.GetDefaultFolder(olFolderTasks)
,使用 将项目添加到该文件夹中MAPIFolder.Items.Add
。
推荐阅读
- node.js - 使用网络钩子和令牌授权 WordPress 网站和 React 应用程序?
- jquery - 使用metro ui验证后如何使用jquery ajax提交表单
- angular - 如何将下拉值作为参数传递?
- javascript - 根据输入文本更新 URL
- android - 切换昼夜切换开关以强制主题
- python - IndexError:列表分配索引超出范围'xxx';'xxx'
- android - MediaBrowserServiceCompat 的 onGetroot() 方法的返回类型?
- git - Git 流程和功能分支的同步
- c - 如何将两个子 fork 进程与共享内存和信号量同步?
- python - BayesSearchCV - lightgbm - 提前停止 - “ValueError:没有足够的值来解压”