Original Attachment not removed

Status
Not open for further replies.
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.

"sd" <dshubhangi@gmail.com> wrote in message

news:615ab412-3a80-4272-9f4d-b930ba2974c8@b25g2000prb.googlegroups.com...
> 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
 
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.

"sd" <dshubhangi@gmail.com> wrote in message

news:3d84b636-4781-4edb-82ff-21e2f8edfdf2@l35g2000pra.googlegroups.com...
> 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.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Auto Forward - Include Attachment and change Subject depending on original sender Outlook VBA and Custom Forms 3
A Creating a rule that both forwards the original attachment and uses a template Using Outlook 11
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
F Forward incoming email with 4 embedded images in the body without original sender Outlook VBA and Custom Forms 22
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
S Email Generated from another program and then edited sends original email. Using Outlook 2
T Original email text not shown when replying or forwarding the email. Using Outlook 9
Bering Forward selected email without the original email appended Outlook VBA and Custom Forms 0
B disappearing original when attach to email Using Outlook 1
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
B Outlook 2013 erratically deleting original file that is attached Using Outlook 0
Z VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
R Retain Original Message When Forwarding With Macro Outlook VBA and Custom Forms 3
D Keep Original html body when forwarding an email Outlook VBA and Custom Forms 7
F Move mails from Deleted Items folder back to its original folder where the mails got deleted Using Outlook 0
Diane Poremsky Foward a Message and CC the Original Recipients Using Outlook 0
H send reminder if no reply received on first or original email using macro Using Outlook 2
H Keep Original email unread after autoreply Outlook VBA and Custom Forms 2
oliv- Why custom form is different from original ipm.contact ? Outlook VBA and Custom Forms 4
S Reply & Forward Date in original message incorrect Using Outlook 2
E Button in body of email to approve/reject with original text Using Outlook 1
S Need CC: to show the original To: recip[ients Using Outlook 4
R Forwarding and keeping Original intact Using Outlook 3
B Auto reply using macro include original email Using Outlook 4
J Image in original e-mail is hyperlinked when a reply with the image is hyerplinked Exchange Server Administration 1
J Adding original email text to outlook message template Outlook VBA and Custom Forms 2
L Creating a Task from Email and Attaching Original Email Outlook VBA and Custom Forms 6
L Auto Forward without presenting the original sender Outlook VBA and Custom Forms 1
J How to redesign the Contact form without losing the original layout? Using Outlook 2
A automatically remove flag from original message when a response was received Using Outlook 2
C Remove iCloud so I can have original outlook calendar and contacts Using Outlook 43
C Hover display of DL shows original owner, not current Using Outlook 2
S Outlook 2k/2k3 Reply or Forward: Signature image replaced by original sender Using Outlook 3
M 2010: sorting by ORIGINAL send date Using Outlook 1
C Create a rule to only check new content in email - disregard original content Using Outlook 3
R Recall Email Message when i'm not the original sender - Outlook 2010 Using Outlook 2
C Outlook/Exchange 2010 Recover Deleted Items to original folder Using Outlook 2
P Reply to original sender, not to forwarder ? Outlook VBA and Custom Forms 1
S -> [O2007]: get the message HTML original source code? Outlook VBA and Custom Forms 6
R Auto Reply with Original Email and any attachments Outlook VBA and Custom Forms 1
R keep track of the original sender Outlook VBA and Custom Forms 3
S Paperclip icon shows without attachment in email under Sent folder Using Outlook 0
M "Attachment Detacher for Outlook" add in, does it update the server copy of the email? Using Outlook 1
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
kkqq1122 How would I add Search for attachment name Outlook VBA and Custom Forms 3
Owl Export Outlook PDF Attachment as JPG? Outlook VBA and Custom Forms 4
Timmon Remove just one attachment before AutoForward Outlook VBA and Custom Forms 0
P File Picker for attachment Outlook VBA and Custom Forms 0
D Forwarding email based on the attachment file type and specific text found on the attachment file name Outlook VBA and Custom Forms 1

Similar threads

Back
Top