"A program has attachment filename open" Message returns

V

Venugopal

hi,

I'm using Outlook 2007 addin with VS2008. I can able to add the attachments
to mailitem,but after that i have got the following message from outlook .

"A program has attachment <filename> open.Changes to this file will be lost
unless you save your changes to another file by clicking the Microsoft Office
Button in the other program, and then clicking Save As."

Note:
1.No such file (<filename>) opened when i got this message.
2.Also i checked with saving mailitem and saving attachments,but the same
message will appear.
3.I also checked when attachment file is not opened,but i face the same
problem
4.I surfed with this problem, i didn't get any solution

Help me as soon as possible
 
K

Ken Slovak - [MVP - Outlook]

Show the code you're using.

It's not intrinsic, I add attachments to items using code and never see that
message.
 
V

Venugopal

hi

i used the below code.And called this function using button click event.

Issues:

1.First time the function runs successfully without any outlook message.

2.If i called that function at second time,then the above mentioned message
will appear.I have cheked with task manager but no such file was run at that
time.

[Outlook 2007 Addin + VS2008]

private void insertAttachments()
{
mail.Attachments.Add("filepath",
OlAttachmentType.olByValue,1,"filename");
mail.Display(true);
mail = null;
}

by,
Venugopal
 
K

Ken Slovak - [MVP - Outlook]

If that's all the code then I don't see why that message is appearing.
However, see if this makes any difference. Since Attachments.Add() is a
function get the returned Attachment object. Then when the procedure ends
release both the mail and attachment objects. Also explicitly declare and
instantiate the Attachments collection so no invisible object variables are
created.

Outlook.Attachments attachs = mail.Attachments;
Outlook.Attachment attach = attachs.Add("filepath",
OlAttachmentType.olByValue,1,"filename");

// blah, blah

attach = null;
attachs = null;
mail = null;

If that doesn't do it then call Marshal.ReleaseComObject() on all 3 objects
before setting them to null and then call GC.Collect().
 

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