Hi Experts,
I am getting error while adding multiple attachments to email. i dont know even whether my code is correct or not.
The error is :
Microsoft Dynamics NAV
---------------------------
A call to System.Net.Mail.AttachmentCollection.Add failed with this message: Cannot access a disposed object.
Object name: 'System.Net.Mail.AttachmentCollection'.
---------------------------
OK
---------------------------
My code is:
----------------------------------------------------------------------------------------------------------------------
Repeat
Note:here i Have a code to run multiple reports from my Record Variable(SubmittedTimeSheetEntryL)
IF REPORT.SAVEASPDF(50053,FileNameL,SubmittedTimeSheetEntryL) THEN BEGIN //Saving Report
MailAttachments := MailMessage.Attachments;
MailAttachment := MailAttachment.Attachment(FileNameL);//FilenameL is different for every report
MailAttachments.Add(MailAttachment);//Adding atttachements
MailMessage.IsBodyHtml := FALSE;
END;
UNtil Mycondition
First attachment is adding successfully but while loop comes to another attachment there it showing the above error.
-----------------------------------------------------------------------------------------------------------------------
Variable Declarations:
Name Datatype sub type
MailAttachements - Dotnet System.Net.Mail.AttachmentCollection.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
MailAttachment - Dotnet System.Net.Mail.Attachment.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
MailMessage - Dotnet System.Net.Mail.MailMessage.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Can any one help to resolve this.
Help should be appreciate.
Thank you
Mahesh