Original Attachment not removed

  • Thread starter Thread starter sd
  • Start date Start date
S

sd

hello

I've VSTO Addin for Outlook 2007.
I'm adding a dummy attachment in BeforeAttachment event & removing
original attachment.
But the attachment list still shows me original attachment along with
dummy attachment.
Besides this when I drag drop or insert attachment the cursor position
changes.
I also need to insert a link at current cursor position.so the cursor
position should not change
for proper link insertion.
Below is the code I'm using -

strMyTmpFilePath = IO.Path.Combine(strMyTmpFilePath,
strMyTmpFileName)
IO.File.AppendAllText(strMyTmpFilePath, "this is a dummy
file")
CurrentMailItem.Attachments.Add(strMyTmpFilePath)
IO.File.Delete(strMyTmpFilePath)
Cancel = True
'Code to add Link at cursor position
Dim ObjSel As Object = CurrentInsp.WordEditor.Application.Selection
With ObjSel
Dim Rg As Object
.MoveRight(Unit:=2, Count:=1) 'wdWord=2
Rg = .range
.Hyperlinks.Add(Anchor:=Rg, Address:=strAttachmentURL _
, TextToDisplay:=strNewLink.ToString)
.InsertAfter(" ")
End With
If Rg IsNot Nothing Then Marshal.FinalReleaseComObject(Rg)
If ObjSel IsNot Nothing Then Marshal.FinalReleaseComObject(ObjSel)


Thanks
 
Try saving the item after you add your new attachment and again after you
remove the old one.
 
Thanks Ken
I saved item after new attachment addition & also after removing the
old one.But no success.Attachment list not refreshed.
Also I don't want to save item (if the user cancels send then I will
have to remove this item from drafts).I reassigned the body
format,that refreshes the attachment list.But in plain text mode link
is not recognized (it is displayed as plain text) & cursor position
again set to starting of message body .
Is there any way so the link gets recognized & also cursor position
doesn't change? If I don't add new attachment ,just remove the old
one & add the link then there is no problem link is recognized &
cursor position also not changed.
 
I don't know about forcing a refresh as well as not changing the cursor
position. However, that's not really an issue, since you can always get the
cursor position first before it changes. That should help.

See if faking out Outlook helps, something like item.Body = item.Body. But I
think you're going to have to save. I usually use a flag in those cases,
first I check the Saved property and then I flag my save if needed, then I
handle the Write() event on the item and if I didn't fire that event by
saving it's the user who did it (or auto-save). Then I can work out if I
need to delete the item from Drafts if necessary.
 
Back
Top