c# - Save custom property in Outlook MailItem permanently -



c# - Save custom property in Outlook MailItem permanently -

i’m coding simple c# programme tries store custom properties in outlook mailitem metadata… created simple method in order write single property:

public static void addcustompropertytoemail(outlook.mailitem mail, string propkey, object propvalue){ if (propvalue system.int32) { // int mail.userproperties.add(propkey, outlook.oluserpropertytype.olinteger,true, outlook.olformatinteger.olformatintegerplain); } else if (propvalue system.double){ // double mail.userproperties.add(propkey,outlook.oluserpropertytype.olcurrency,true,outlook.olformatcurrency.olformatcurrencydecimal); } mail.userproperties[propkey].value = propvalue; mail.save(); }

and in order read single property:

public static string getcustompropertyfromemail(outlook.mailitem mail, string propkey){ homecoming (mail.userproperties[propkey] != null) ? mail.userproperties[propkey].value.tostring() : null; }

when print @ console each property i’ve added before print goes fine if read property same mailitem type stored in memory… example:

static void main(string[] args){ outlook.application outlookobj = new outlook.application(); outlook.mailitem m1 = getcurrentemailitem(outlookobj); addcustompropertytoemail(m1, “int”, 100); addcustompropertytoemail(m1, “double”, 2.0003); console.writeline(getcustompropertyfromemail(m2, “int”)); console.writeline(getcustompropertyfromemail(m2, “double”)); if (m1 != null) marshal.releasecomobject(m1); console.readkey(); }

this programme works fine, prints values!!!

but follow code not, returns null in each case:

static void main(string[] args){ outlook.application outlookobj = new outlook.application(); outlook.mailitem m1 = getcurrentemailitem(outlookobj); addcustompropertytoemail(m1, “int”, 100); addcustompropertytoemail(m1, “double”, 2.0003); m1.saveas(@”c:\pws\mymail.msg”, outlook.olsaveastype.olmsg); outlook.mailitem m2 = (outlook.mailitem)outlookobj.createitem(outlook.olitemtype.olmailitem); m2 = (outlook.mailitem)outlookobj.session.openshareditem(@”c:\pws\mymail.msg”); // here programme prints null console.writeline(getcustompropertyfromemail(m2, “int”)); console.writeline(getcustompropertyfromemail(m2, “double”)); if (m2 != null) marshal.releasecomobject(m2); console.readkey(); }

my question is: how can save/store custom property in mailitem, , perchance save related msg file in pws , read these custom properties in sec time???

you need phone call mailitem.save persist changes.

c# outlook

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -