G
gwolinsky
I have run across a strange problem. I have created a simple Outlook
2003 Add-in using VSTO in VS2005.
When a new mail message inspector is opened, I add a button to the
inspector's command bar. This button simply appends some standard text
on the end of whatever subject line text is already there if it has not
already been done. I check to see if the standardized text is on the
end of subject. If it's not, I add it.
It's really rather simple and works great (even with multiple
inspectors open) except for one strange issue.
When I enter some text in the subject line, if I DON'T exit the subject
textbox, whatever text I've entered doesn't show up in the mail message
object. So, when I go to add the standard text, whatever text I've
already keyed isn't there and my code erases it when it resets the
subject textbox.
If I key in some text and EXIT the subject textbox, then, when I click
the button, the mail object sees the text just fine and appends the
standard text to it as it should.
Has anyone else seen this behavior? It seems that the text in the
subject line textbox is not available to the mail message object until
you exit the field.
Any help or information would be greatly appreciated.
Sincerely,
Glen Wolinsky
Code Below
---------------------------
Public Class ThisApplication
Const PRIV_TEXT As String = " - Confidential Attorney Work Product
- Subject to Privilege"
Private WithEvents confidentialButton As Office.CommandBarButton
Private WithEvents olInspectors As Outlook.Inspectors =
Me.Inspectors
Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Me.Startup
End Sub
Private Sub ThisApplication_Shutdown(ByVal sender As Object, ByVal
e As System.EventArgs) Handles Me.Shutdown
End Sub
Private Sub NewInspector(ByVal insp As Outlook.Inspector) Handles
olInspectors.NewInspector
If TypeOf (insp.CurrentItem) Is Outlook.MailItem Then
Dim bar As Office.CommandBar = insp.CommandBars("Standard")
confidentialButton =
bar.Controls.Add(Office.MsoControlType.msoControlButton,
Temporary:=True)
With confidentialButton
.Caption = "Privilaged Tag"
.Style = MsoButtonStyle.msoButtonCaption
AddHandler .Click, AddressOf confidentialButton_Click
End With
End If
End Sub
Private Sub confidentialButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Dim draft As Outlook.MailItem =
DirectCast(ActiveInspector.CurrentItem, Outlook.MailItem)
If Not draft.Subject.EndsWith(PRIV_TEXT) Then
draft.Subject = Trim(draft.Subject) & PRIV_TEXT
End If
End Sub
End Class
2003 Add-in using VSTO in VS2005.
When a new mail message inspector is opened, I add a button to the
inspector's command bar. This button simply appends some standard text
on the end of whatever subject line text is already there if it has not
already been done. I check to see if the standardized text is on the
end of subject. If it's not, I add it.
It's really rather simple and works great (even with multiple
inspectors open) except for one strange issue.
When I enter some text in the subject line, if I DON'T exit the subject
textbox, whatever text I've entered doesn't show up in the mail message
object. So, when I go to add the standard text, whatever text I've
already keyed isn't there and my code erases it when it resets the
subject textbox.
If I key in some text and EXIT the subject textbox, then, when I click
the button, the mail object sees the text just fine and appends the
standard text to it as it should.
Has anyone else seen this behavior? It seems that the text in the
subject line textbox is not available to the mail message object until
you exit the field.
Any help or information would be greatly appreciated.
Sincerely,
Glen Wolinsky
Code Below
---------------------------
Public Class ThisApplication
Const PRIV_TEXT As String = " - Confidential Attorney Work Product
- Subject to Privilege"
Private WithEvents confidentialButton As Office.CommandBarButton
Private WithEvents olInspectors As Outlook.Inspectors =
Me.Inspectors
Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Me.Startup
End Sub
Private Sub ThisApplication_Shutdown(ByVal sender As Object, ByVal
e As System.EventArgs) Handles Me.Shutdown
End Sub
Private Sub NewInspector(ByVal insp As Outlook.Inspector) Handles
olInspectors.NewInspector
If TypeOf (insp.CurrentItem) Is Outlook.MailItem Then
Dim bar As Office.CommandBar = insp.CommandBars("Standard")
confidentialButton =
bar.Controls.Add(Office.MsoControlType.msoControlButton,
Temporary:=True)
With confidentialButton
.Caption = "Privilaged Tag"
.Style = MsoButtonStyle.msoButtonCaption
AddHandler .Click, AddressOf confidentialButton_Click
End With
End If
End Sub
Private Sub confidentialButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Dim draft As Outlook.MailItem =
DirectCast(ActiveInspector.CurrentItem, Outlook.MailItem)
If Not draft.Subject.EndsWith(PRIV_TEXT) Then
draft.Subject = Trim(draft.Subject) & PRIV_TEXT
End If
End Sub
End Class