Outlook VSTO 禁用主题更改后要求保存邮件的提示
Outlook VSTO disable prompt asking to save message after subject changes
我编写了一个 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));
}
}
}
}
您在修改主题后从未调用 MailItem.Save()
属性
我编写了一个 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));
}
}
}
}
您在修改主题后从未调用 MailItem.Save()
属性