Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
in My web application i need to send mail with attchments that are from
fileupload control but neeed to add multiple attchments.

i took one grid and aon attch whatevre i added i am adding in grid ,but the problem is if i am selecting single file i am able to send mail,
but if i select multiple files i am not able to send mail..please help

my code is like:

C#
string FilePath = uploadFile.PostedFile.FileName;
  string filenameadding = uploadFile.FileName.ToString(); ;
     DataTable dt1 = new DataTable();//every time on button click new datatable will be created
      dt1.Columns.Add("filename");
if (uploadFile.HasFile)
            {
                if (ViewState["Attachments"] != null)
                {
             foreach (GridViewRow row in grdfiledetails.Rows)
                    {

                        DataRow dr = dt1.NewRow();
                        Label lbl = (Label)row.FindControl("lblfilename");
 dr["filename"] = lbl.Text;
                        dt1.Rows.Add(dr);
                    }
                }
DataRow dtrow = dt1.NewRow();
                dtrow["filename"] = uploadFile.FileName.ToString();
                dt1.Rows.Add(dtrow);
                if (ViewState["Attachments"] != null)
                {
                    ViewState.Remove("Attachments");
                }
                ViewState["Attachments"] = dt1;
                grdfiledetails.DataSource = dt1;
                grdfiledetails.DataBind();
            }


this is for adding to grid.....now for sending mail

my code is:
C#
mail.ReplyTo = new MailAddress(emailaddr);
                mail.Priority = MailPriority.Normal;
                 if (uploadFile.PostedFile != null)//adding file upload from upload control
                {
                    if (grdfiledetails.Rows.Count > 0)
                    {
                        //foreach (GridViewRow gvrow in grdfiledetails.Rows)
                        //{
                        //    Label lblgridfile = (Label)gvrow.FindControl("lblfilename");
                        //    Attachment attachFile = new Attachment(uploadFile.PostedFile.InputStream, lblgridfile.Text.ToString());
                        //    mail.Attachments.Add(attachFile);
                        //}
                        for(int i=0;i<grdfiledetails.Rows.Count;i++)
                        {
                            string strFileName = Path.GetFileName(uploadFile.PostedFile.FileName);


                        }
                    }
                    else//if added only one file
                    {
                        string strFileName = Path.GetFileName(uploadFile.PostedFile.FileName);
                        Attachment attachFile = new Attachment(uploadFile.PostedFile.InputStream, strFileName);
                        mail.Attachments.Add(attachFile);


                    }



please help...i am wrong some where..please help and excuse me if it is basic question
Posted
Updated 9-Jan-14 1:20am
v3
Comments
Sibasisjena 9-Jan-14 7:47am    
You are selecting multiple files at a time or you are selecting multiple files one after another ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900