I m试图储存用户特性中的一些数据,然后将邮件发至.msg文档,(later/em>)将文件上载至用户财产。
问题在于:在重载档案后,我没有任何用户财产。
Im 采用《2010年展望》32 轨道
这里是一部体现以下行为的法典:
Outlook.MailItem originalItem = ((MailItemWrapper)this.Item)._item;
var path = System.IO.Path.GetTempFileName() + ".msg";
var propName = "ActionId123456789";
// Set a user property "ActionId" with value "test"
var ps = originalItem.UserProperties;
var p = ps.Find(propName);
if (p == null)
p = ps.Add(propName, Outlook.OlUserPropertyType.olText, Type.Missing);
p.Value = "test";
// Save to a temp file
originalItem.Save(); // --> I also tried without this line
originalItem.SaveAs(path);
// Chech the the property is correctly set
p = originalItem.UserProperties[propName];
if (p != null)
Console.WriteLine(p.Value); // ---> Show test
// Open the temp file
Outlook.MailItem newItem = AddinModule.CurrentInstance.OutlookApp.Session.OpenSharedItem(path) as Outlook.MailItem;
// Check that the property still exists
p = newItem.UserProperties[propName];
if (p != null)
Console.WriteLine(p.Value); // ---> Not executed: p is NULL !
是否有人知道如何这样做?
Instead of using OpenSharedItem
, I also tried opening the mail using Process.Start
, but in this case the user property is also null ...
BTW 这份法典是一个测试样本,因此它有t dispose
,所有COM参考文献都正确无误。