Trying to go two routes with this. The goal is to let someone attach a file and then on _ItemSend event to run a Regexp to detect certain strings in the filename and then to a Cancel=True or Cancel=False. I have the following code, but the basic problem I'm having is converting the mailItem.Attachments to a String to actually run it through the Regexp. I get alot of errors saying it can't be converted to a String...any ideas?
Public Sub Application_ItemSend(ByVal Item As Object, _
ByRef Cancel As Boolean) Handles Application.ItemSend
Dim mailItem As Outlook.MailItem = TryCast(Item, Outlook.MailItem)
If mailItem IsNot Nothing Then
Dim attachments = mailItem.Attachments
For Each attachment As Outlook.Attachment In attachments
AttachmentQuery(attachment, mailItem, Cancel)
Next attachment
End If
Dim instance As String
Dim AttachmentMatchResults As MatchCollection
Dim attachments1 = mailItem.Attachments
instance = attachments1.ToString
Dim returnValue As String
returnValue = instance.ToString
Dim RegexObj2 As New Regex("^.*(names|playlist|roster).*$", RegexOptions.Multiline)
AttachmentMatchResults = RegexObj2.Matches(returnValue)
If RegexObj2.IsMatch(returnValue) Then
MsgBox("A key file has been found", MsgBoxStyle.OkCancel)
Cancel = True
Else
Cancel = False
End If