473,469 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

email multiple files attachments

hi i have 5 checkboxes i would like to when the user click on 1 or multiple
checkbox i would like to email 1 or multiple files attachments to them
ex: mailMsg.Attachments.Add(myAttachment+i);
but getting error: Specified cast is not valid.

thank you in advance

my code below:
MailAttachment myAttachment0 = new MailAttachment
(this.Server.MapPath("../serverForms/Auto_Form_01.pdf"),
MailEncoding.Base64);
MailAttachment myAttachment1 = new MailAttachment
(this.Server.MapPath("../serverForms/Homeowners_Form_01.pdf",
MailEncoding.Base64);
MailAttachment myAttachment3 = new MailAttachment
(this.Server.MapPath("../serverForms/Condo_Coop_Form_01.pdf",
MailEncoding.Base64);
MailAttachment myAttachment4 = new MailAttachment
(this.Server.MapPath("../serverForms/Renters_Form_01.pdf",
MailEncoding.Base64);

for (int i=0;i<this.CheckBoxListForms.Items.Count;i++)
{
if (this.CheckBoxListForms.Items[i].Selected)
{

// would like to attach the appropriate checkbox file in my checkbox
list
// GETTING ERROR - Exception Details: System.InvalidCastException:
Specified cast is not valid.
mailMsg.Attachments.Add(myAttachment+i);

}

}
Nov 18 '05 #1
1 2316
You are trying to add a number and a MailAttachment. There is not cast for
it.

If you want to keep your for loop code and use the i (counter) you will need
to put all the MailAttachments in a variable.

MailAttachment [] attachments = new MailAttachment[5];
attachments[0] = new MainAttachment(
this.Server.MapPath("../serverForms/Auto_Form_01.pdf"),
MailEncoding.Base64);
....
add the rest of them.

In your for loop change this code:
mailMsg.Attachments.Add(myAttachment+i);
to:
mailMsg.Attachments.Add( attachments[i] );

You can not add a integer and a MailAttachment together and get a new
variable name. If that sentence doesn't make any sense, it is because it
doesn't make any sense and that is why you received a Specified cast is not
valid error.

HTH,

bill
"nabil m" <na***@hagedorn.com> wrote in message
news:uG*************@TK2MSFTNGP10.phx.gbl...
hi i have 5 checkboxes i would like to when the user click on 1 or multiple checkbox i would like to email 1 or multiple files attachments to them
ex: mailMsg.Attachments.Add(myAttachment+i);
but getting error: Specified cast is not valid.

thank you in advance

my code below:
MailAttachment myAttachment0 = new MailAttachment
(this.Server.MapPath("../serverForms/Auto_Form_01.pdf"),
MailEncoding.Base64);
MailAttachment myAttachment1 = new MailAttachment
(this.Server.MapPath("../serverForms/Homeowners_Form_01.pdf",
MailEncoding.Base64);
MailAttachment myAttachment3 = new MailAttachment
(this.Server.MapPath("../serverForms/Condo_Coop_Form_01.pdf",
MailEncoding.Base64);
MailAttachment myAttachment4 = new MailAttachment
(this.Server.MapPath("../serverForms/Renters_Form_01.pdf",
MailEncoding.Base64);

for (int i=0;i<this.CheckBoxListForms.Items.Count;i++)
{
if (this.CheckBoxListForms.Items[i].Selected)
{

// would like to attach the appropriate checkbox file in my checkbox
list
// GETTING ERROR - Exception Details: System.InvalidCastException:
Specified cast is not valid.
mailMsg.Attachments.Add(myAttachment+i);

}

}

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: tabonni | last post by:
Hi I try to grab the checked files from HTML page and then send those PDF files as attachments. It can just send email, there are no PDF files attached. Can anybody point out my error? My...
2
by: Steve | last post by:
How do you programatically save files that are attached to an email to a specified folder? It could be one file or multiple files attached to the email. Can it be done if Outlook Express is being...
2
by: Steve | last post by:
How do you programatically save files that are attached to an email to a specified folder? It could be one file or multiple files attached to the email. Can it be done if Outlook Express is being...
2
by: EdWhyatt | last post by:
Hi all, I hope there is someone out there who can help me out - it has to be something obvious. I am simulating mail traffic, and want to include multiple attachments to my mail. I have created...
10
by: Walshi | last post by:
Hi all, I'm a relative newby to access and VBA etc. My forms and tables etc are working great and saving lots of time...However... I have two databases with the exact same table format. I want...
2
by: oyster | last post by:
I find that the existing email moudle is some hard for me to understand, especially the part of how to set the CC, BCC and attach the files. Is there any more easy one like this p-code? import...
8
alpnz
by: alpnz | last post by:
Hi, I have a need to send snap reports to various shipping agents. E.g. A PalletCard, A FreightNote, A Consignment Advice, and an Export declaration of Conformity. It is easy enough to code a...
2
by: David Veeneman | last post by:
My web app creates several temporary files, then attaches them to an email that it sends out. When the app attches the documents to the email, .NET locks the files. My problem is that they aren't...
1
by: budyerr | last post by:
All, I am trying to build a email submission form using asp.net. I currently have a web form page that will upload to my webhosting server, attach to email then delete the file after sending. ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.