'getting the most current value of Subject line of an Outlook AppointmentItem
I have issues accessing the actual typed-in text in Subject field of an AppointmentItem. I have created an Outlook 2010 add-in that has a callback from a custom button from the ribbon. I can get the value of the Subject field except if someone is clicking the button right after typing the subject (and not changing control focus). In these cases I'm getting the previous value of the Subject and not the recently typed in value. (for a newly created Meeting Invitation I get a null value)
public void ToggleMeetingPlace_Callback(Office.IRibbonControl control)
{
if ((control!=null)&&(control.Id == "toggleMeetingPlace"))
{
var item = control.Context as Outlook.Inspector;
if ((item != null) && (item.CurrentItem != null))
{
Outlook.AppointmentItem m_item = item.CurrentItem as Outlook.AppointmentItem;
string subject = m_item.Subject;
// some action
}
}
}
However if I start to debug I see some interesting behavior in the watch window: - directly watching m_item.Subject returns still the old value - but if I set up a watch for m_item and then expand the Dynamic members all of a sudden the value is updated to the current text.
I guess the dynamic view in this case has some side effects that come in handy... I just can't figure out how to do this from code.
Solution 1:[1]
Its happening because you have placed your curser in the subject field of your item. If you remove the focus from subject field it will work.
Yes you are right by expanding dynamic view all of a sudden subject text appears, but that my be due to delay or something that i don't know.
Solution 2:[2]
m_item - A variable that represents an AppointmentItem object
m_item.Save() - "trigger" dynamic view obj, now you have data on m_item.Subject
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Indresh Tripathi |
| Solution 2 | eden m |
