none
How to keep user properties over Reply RRS feed

  • Question

  • Hi,

    I need to keep my user properties over the reply event. If I do forward, they are kept, however if I click reply, my user properties are cleared. Any idea?

    Thanks a lot

    Filip

    Office 2010, W7
    Tuesday, March 20, 2012 9:46 AM

Answers

  • you have to track all possible ways of choosing 'replay' and 'replay to all' actions (for example keeping track of selection and selection changes and subscribing to Replay* events) and manually copy needed user properties to new mail
    Tuesday, March 20, 2012 10:38 AM
  • If you are using C# any overloaded events (that have the same name as a method such as Reply) have to be approached in a different way to get at the event that overloads the method.
     
    For example:
     
    Outlook.ItemEvents_Event _itemEvents = null;

    _itemEvents = (Outlook.ItemEvents_Event)_mail; // _mail is an instantiated MailItem

    _itemEvents.Reply += new Microsoft.Office.Interop.Outlook.ItemEvents_ReplyEventHandler(_itemEvents_Reply);


    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Filip Mateasko" <=?utf-8?B?RmlsaXAgTWF0ZWFza28=?=> wrote in message news:5333c90c-81b5-4a35-b7f0-6f5d361f6fc7...
    this is what I posted

    Ken Slovak MVP - Outlook
    Wednesday, March 21, 2012 2:23 PM
    Moderator
  • I would do that, but I think I must keep the reference to the original item, since I need to handle it's Reply event.

    I did a lot of tests and I have finally probably found the problem, however if you had some explanation why it is so, it would be very helpful for me.

    the problematic code is here

    void OnMailReply(object Response, refbool Cancel)         { OutlookItem oItem = newOutlookItem(Response);                 oItem.SetUserProperty(MY_PROPERTY, OL.OlUserPropertyType.olText, _rememberedValue);                 oItem.Save();             }         }

    If I don't do oItem.Save, it works ! With it I have those problems.... Why is this so?

    Wednesday, March 21, 2012 9:44 PM

All replies

  • you have to track all possible ways of choosing 'replay' and 'replay to all' actions (for example keeping track of selection and selection changes and subscribing to Replay* events) and manually copy needed user properties to new mail
    Tuesday, March 20, 2012 10:38 AM
  • Thanks Damian,

    so I do that, it works, but I have another problem.

    First I descrive what I do:

    I added event handler to INspectors.NewInspector

    _inspectors = App.Inspectors;
    _inspectors.NewInspector += OnNewInspectorOpen;
     
    void OnNewInspectorOpen(OL.Inspector newInspector)
            {
                if (newInspector.CurrentItem is OL.MailItem)
                {
                    if(_openItem !=null)
                        ((OL.ItemEvents_10_Event)_openItem).Reply -= OnMailReply;
     
                    _openItem = ((OL.MailItem)newInspector.CurrentItem);
                    ((OL.ItemEvents_10_Event)_openItem).Reply += OnMailReply;
                    OutlookItem oItem = newOutlookItem(_openItem);
                    object outValue
                    if (oItem.HasUserProperty(MY_PROPERTY, out outValue) )
                    {   _rememberedValue = outValue.ToString();
                    }
                    else
                    {
                        _rememberedValue = string.Empty;
                    }
                }
     
            }
     
            void OnMailReply(object Response, refbool Cancel)
            {
    OutlookItem oItem = newOutlookItem(Response);
                    oItem.SetUserProperty(MY_PROPERTY, OL.OlUserPropertyType.olText, _rememberedValue);
                    oItem.Save();
    
                }
            }

    My questions are:

    1) I was not able to find Reply event in MailItem intelisense - the only possibility is to retype it as I do. Is this correct? In MSDN it's writte that MailItem has Reply event...

    2) I do no modification to original item, however if I click Reply and want to close th original (not the new!) item, it says "The attachment of the message have ben changed, do you want to save changes ?" But I have NO attachment there! Any idea what to do with it?

    Thanks a lot

    Filip


    Wednesday, March 21, 2012 1:12 PM
  • ad 1. Maybe you are storing mailItem not as a MailItem type but rather as _MailItem? Check this.

    ad 2. where do you close original item? i do not see it in your code. You could call Close on inspector with value param to discard any changes.

    and general suggestion - handling only 'replay' button on mail opened in separate window will not save you - users can click replay on item in explorer or use a shortcut or button in ribbon.

    Wednesday, March 21, 2012 1:30 PM
  • ad 1 - No, I used MailItem. However, I've just  found, that if I use MailItemClass, I can find there event ItemEvents_10_Event_Reply

                    _openItem = ((OL.MailItemClass )newInspector.CurrentItem);
                    _openItem.ItemEvents_10_Event_Reply += OnMailReply;
    

    Ad2 - It is something strange - I changed nothing and now it works - previously it didnt close the original message when new Inpector was created for Reply and when I wanted to close Inspector windows of the original message, it said me what I wrote, however it suddenly started to close it automatically. I don't know what happened. 

    Thanks for your suggestions - so I'm gonig to investigate where and how is possible to handle such events... ;-) 

    Filip

    Wednesday, March 21, 2012 1:42 PM
  • ad 1 - are you using official PIA assemblies or did you generate your own interop dlls?
    Wednesday, March 21, 2012 2:03 PM
  • Offical one. At least I hope so... it was already integrated in Visual Studio, I think. I don't remember that I did something special...
    Wednesday, March 21, 2012 2:06 PM
  • C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Outlook.dll 

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Outlook.dll
    on Microsoft Windows Seven x64 Professional Edition Version 6.1 (build 7601) Service pack 1 




    File Version Information : 


    Version language : Czech (Czech Republic)
          CompanyName : Microsoft Corporation
          FileDescription : Microsoft.Office.Interop.Outlook
          FileVersion : 14.0.4760.1000
          InternalName : Outlook Primary Interop Assembly
          LegalCopyright : © 2010 Microsoft Corporation.  All rights reserved.
          LegalTrademarks1 : Microsoft® is a registered trademark of Microsoft Corporation.
          LegalTrademarks2 : Windows® is a registered trademark of Microsoft Corporation.
          OriginalFilename : Outlook Primary Interop Assembly
          ProductName : Microsoft Office 2010
          ProductVersion : 14.0.4760.1000


    Creation Date : 18/01/2011  18:27:04 
    Last Modif. Date : 18/01/2011  18:27:04 
    Last Access Date : 12/02/2012  23:17:34 
    FileSize : 972664 bytes ( 949.867 KB,  0.928 MB ) 
    FileVersionInfoSize : 2588 bytes  
    File type : Application (0x1) 
    Target OS : Win32 API (Windows NT) (0x40004) 
    File/Product version : 14.0.4760.1000 / 14.0.4760.0
    Language : Czech (Czech Republic) (0x0) 
    Character Set : 1252 (ANSI - Latin 1 (US, Western Europe)) (0x4E4) 


    Build Information : 
    Debug Version : no 
    Patched Version : no 
    Prerelease Version : no 
    Private Version : no 
    Special Build : no 

    Wednesday, March 21, 2012 2:08 PM
  • check properties on project's reference to Interop.Outlook assembly - especially Path value - does it point to official PIA?
    Wednesday, March 21, 2012 2:15 PM
  • this is what I posted
    Wednesday, March 21, 2012 2:16 PM
  • If you are using C# any overloaded events (that have the same name as a method such as Reply) have to be approached in a different way to get at the event that overloads the method.
     
    For example:
     
    Outlook.ItemEvents_Event _itemEvents = null;

    _itemEvents = (Outlook.ItemEvents_Event)_mail; // _mail is an instantiated MailItem

    _itemEvents.Reply += new Microsoft.Office.Interop.Outlook.ItemEvents_ReplyEventHandler(_itemEvents_Reply);


    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Filip Mateasko" <=?utf-8?B?RmlsaXAgTWF0ZWFza28=?=> wrote in message news:5333c90c-81b5-4a35-b7f0-6f5d361f6fc7...
    this is what I posted

    Ken Slovak MVP - Outlook
    Wednesday, March 21, 2012 2:23 PM
    Moderator
  • Well, I did some modifications (to catch all possibilities I handle Explorer.SlectionChange event to store values for later use in Reply event handler)

     private OL.ItemEvents_Event _openItem;
    

    void _currentExplorer_SelectionChange()         {             if (_openItem != null)             {                 ((OL.ItemEvents_Event)_openItem).Reply -= OnMailReply;                 Marshal.ReleaseComObject(_openItem);             }             if (_currentExplorer.Selection.Count == 1)             {                 if (!(_currentExplorer.Selection[1] is OL.ItemEvents_Event))                     return;                 _openItem = (OL.ItemEvents_Event)_currentExplorer.Selection[1];                 _openItem.Reply  += OnMailReply;                 OutlookItem oItem = new OutlookItem(_openItem);                 object outValue; if (oItem.HasUserProperty(MY_PROPERTY, out outValue) )                 {                     _remValue = uploadMode.ToString();                 }                 else                 {                     _remValue = string.Empty;                 }                 Marshal.ReleaseComObject(oItem);             }         }

                     

    but now it agains displays that Message "User properties of message have been changed, do you want to save changes?" But I didn't changed anything!!"

    just to give you full code:

    	public bool HasUserProperty(string propertyName, out object propertyValue)
           {
               string fullName = "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/" + propertyName;
               if (PropertyAccessor == null)
                   throw new System.Exception("Property accessor is not accessible.");
               try
               {
                   propertyValue = PropertyAccessor.GetProperty(fullName);
                   return true;
               }
               catch (System.Exception)
               {
                   propertyValue = null;
                   return false;
               }
           }
    	public OL.PropertyAccessor PropertyAccessor
            {
                get
                {
                    return this.GetPropertyValue(OlPropertyAccessor) as OL.PropertyAccessor;
                }
            }

    Wednesday, March 21, 2012 2:33 PM
  • A line like this makes no sense:
     if (!(_currentExplorer.Selection[1] is OL.ItemEvents_Event))
     
    A selected item is a mail item, or a post item, or an appointment item, or ... It's not an event collection. You need to instantiate an actual Outlook item type before you try to handle its events.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Filip Mateasko" <=?utf-8?B?RmlsaXAgTWF0ZWFza28=?=> wrote in message news:f4b6d629-010f-49a3-ae58-239053363eeb...

    Well, I did some modifications (to catch all possibilities I handle Explorer.SlectionChange event to store values for later use in Reply event handler)

     private OL.ItemEvents_Event _openItem;
    

    void _currentExplorer_SelectionChange()         {             if (_openItem != null)             {                 ((OL.ItemEvents_Event)_openItem).Reply -= OnMailReply;                 Marshal.ReleaseComObject(_openItem);             }             if (_currentExplorer.Selection.Count == 1)             {                 if (!(_currentExplorer.Selection[1] is OL.ItemEvents_Event))                     return;                 _openItem = (OL.ItemEvents_Event)_currentExplorer.Selection[1];                 _openItem.Reply  += OnMailReply;                 OutlookItem oItem = new OutlookItem(_openItem);                 object outValue; if (oItem.HasUserProperty(MY_PROPERTY, out outValue) )                 {                     _remValue = uploadMode.ToString();                 }                 else                 {                     _remValue = string.Empty;                 }                 Marshal.ReleaseComObject(oItem);             }         }

                     

    but now it agains displays that Message "User properties of message have been changed, do you want to save changes?" But I didn't changed anything!!"

    just to give you full code:

    	public bool HasUserProperty(string propertyName, out object propertyValue)
           {
               string fullName = "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/" + propertyName;
               if (PropertyAccessor == null)
                   throw new System.Exception("Property accessor is not accessible.");
               try
               {
                   propertyValue = PropertyAccessor.GetProperty(fullName);
                   return true;
               }
               catch (System.Exception)
               {
                   propertyValue = null;
                   return false;
               }
           }
    	public OL.PropertyAccessor PropertyAccessor
            {
                get
                {
                    return this.GetPropertyValue(OlPropertyAccessor) as OL.PropertyAccessor;
                }
            }


    Ken Slovak MVP - Outlook
    Wednesday, March 21, 2012 2:37 PM
    Moderator
  • I've changed it and keeping reference

    private OL.MailItem  _openItem;

    but it still doesnt solve the problem, that if I open mail for read and click Reply, the original item stays open and when I wnat to close it it says "Properties of message have neen changed....."

    Any idea what could be the problem ? Is it problem that I keep the reference to the selected item?

    Wednesday, March 21, 2012 2:44 PM
  • Possibly something is changing when you're opening the item or in your handling of it. I think you're going to get that message whenever you close the item unless you figure out what is happening. You can try releasing all references to the original item and just keep a reference to the EntryID so you can grab it again if necessary.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Filip Mateasko" <=?utf-8?B?RmlsaXAgTWF0ZWFza28=?=> wrote in message news:f9e339d5-5dd1-4c7e-be11-810e5214621f...

    I've changed it and keeping reference

    private OL.MailItem  _openItem;

    but it still doesnt solve the problem, that if I open mail for read and click Reply, the original item stays open and when I wnat to close it it says "Properties of message have neen changed....."

    Any idea what could be the problem ? Is it problem that I keep the reference to the selected item?


    Ken Slovak MVP - Outlook
    Wednesday, March 21, 2012 4:54 PM
    Moderator
  • I would do that, but I think I must keep the reference to the original item, since I need to handle it's Reply event.

    I did a lot of tests and I have finally probably found the problem, however if you had some explanation why it is so, it would be very helpful for me.

    the problematic code is here

    void OnMailReply(object Response, refbool Cancel)         { OutlookItem oItem = newOutlookItem(Response);                 oItem.SetUserProperty(MY_PROPERTY, OL.OlUserPropertyType.olText, _rememberedValue);                 oItem.Save();             }         }

    If I don't do oItem.Save, it works ! With it I have those problems.... Why is this so?

    Wednesday, March 21, 2012 9:44 PM
  • What is OutlookItem oItem = newOutlookItem(Response); ? I
     
    Is that storing an instance of the item before you add a user property to the item? It sounds like you're creating a conflict situation. I would check for more than one instance or reference to the same item.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Filip Mateasko" <=?utf-8?B?RmlsaXAgTWF0ZWFza28=?=> wrote in message news:74e00ac8-1665-4ac1-97c2-df2d94132841...

    I would do that, but I think I must keep the reference to the original item, since I need to handle it's Reply event.

    I did a lot of tests and I have finally probably found the problem, however if you had some explanation why it is so, it would be very helpful for me.

    the problematic code is here

    void OnMailReply(object Response, refbool Cancel)         { OutlookItem oItem = newOutlookItem(Response);                 oItem.SetUserProperty(MY_PROPERTY, OL.OlUserPropertyType.olText, _rememberedValue);                 oItem.Save();             }         }

    If I don't do oItem.Save, it works ! With it I have those problems.... Why is this so?


    Ken Slovak MVP - Outlook
    Wednesday, March 21, 2012 9:56 PM
    Moderator
  • OutlookItem class is an Outlook helper class http://msdn.microsoft.com/en-us/library/hh780900.aspx

    It keeps the reference to the item, but to RESPONSE, not the original one. Original item is referenced as _openItem and it is not used here. I don't see any conflict, do you?

    F.

    Thursday, March 22, 2012 8:51 AM
  • Offhand I don't see anything, but I doubt that I've seen all the code you have. In addition, you might want to force a complete release of any references you have to the item by calling Marshal.ReleaseComObject() on it, setting it to null, and calling the garbage collector.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Filip Mateasko" <=?utf-8?B?RmlsaXAgTWF0ZWFza28=?=> wrote in message news:1722efd6-7a56-4b79-b39a-749bcec792f8...

    OutlookItem class is an Outlook helper class http://msdn.microsoft.com/en-us/library/hh780900.aspx

    It keeps the reference to the item, but to RESPONSE, not the original one. Original item is referenced as _openItem and it is not used here. I don't see any conflict, do you?

    F.


    Ken Slovak MVP - Outlook
    Thursday, March 22, 2012 1:19 PM
    Moderator