我写了一个VSTO功能区按钮来批量更改现有MailItem上的主题。但是,它不是100%的工作时间。我怀疑在主题更改后要求我保存电子邮件的提示阻止了主题更改。
如何以编程方式抑制对话框,以便我可以批量更改主题,然后取消禁止对话框。
public void EditSubject()
{
var explorer = _OutlookApplication.ActiveExplorer();
var selection = explorer.Selection;
List<MailItem> mailItems = new List<MailItem>();
foreach(var item in selection)
{
var mailitem = item as MailItem;
if(mailitem != null) mailItems.Add(mailitem);
}
if(mailItems.Count > 0)
{
using (var form = new FormEditSubject())
{
form.Subject = mailItems[0].Subject;
if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// changing subject works, but does not work 100% of the time.
// Save prompt dialog shows when closing outlook.
mailItems.ForEach(item => item.Subject = form.Subject);
System.Windows.Forms.MessageBox.Show(string.Format("{0} MailItems subject edited to: {1}", mailItems.Count, form.Subject));
}
}
}
}
答案 0 :(得分:0)
修改主题属性后,您永远不会调用MailItem.Save()