unable to save attachment

S

sd

hello
I've VSTO addin for Outlook 2003.I need to interrupt
MailItem_AttachmentAdd event , save the attachement in temp folder ,
add the filepath of

saved attachment as link in message body of mailitem and remove
Original attachment.below code works for Plain text/HTML format.But it
throws

exception when Rich Text format is selected and word is editor.

CurrentMailItem_AttachmentAdd()

strMyTmpFileName = Attachment.FileName 'throws exception however
Attachment.DisplayName works fine
strMyTmpFilePath = IO.Path.Combine(strMyTmpFilePath, strMyTmpFileName)
'strMyTmpFilePath is Temporary folder path
IO.File.AppendAllText(strMyTmpFilePath, "Uploading Original file... ,
this is a dummy file")
CurrentMailItem.Attachments.Add(strMyTmpFilePath)
IO.File.Delete(strMyTmpFilePath)

strTmpFilePath = IO.Path.Combine(strTmpFilePath, Attachment.FileName)
'strTmpFilePath is another Temporary folder path
Attachment.SaveAsFile(strTmpFilePath)
'throws exception Cannot save the attachment. Outlook cannot do this
action on this type of attachment.

strAttachmentURL = GetAttachmentURL(strTmpFilePath)
CurrentMailItem.Body += vbNewLine + strAttachmentURL

Dim mydeleteThread As New Thread(AddressOf DeleteAttachment)
mydeleteThread.Start(Attachment.FileName)
mydeleteThread = Nothing

Sub DeleteAttachment(ByVal strFilePath As Object)
If CurrentMailItem IsNot Nothing AndAlso bMsgSent = False Then
CurrentMailItem.Attachments
(strFilePath.ToString).Delete()
' throws "Operaion failed" exception When Word is not editor and Rich
text is message format
End If

Besides this it also throws "catastrophic failure" after running
CurrentMailItem_AttachmentAdd() event.
What am I missing?

Thanks
 
K

Ken Slovak - [MVP - Outlook]

Other than adding try...catch blocks to trap any failures like that I have
nothing to advise on that problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top