Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Gridview, in which i am using Fileupload Control as an item template.
there are max 6 rows can be generated in this gridview.
As I am sending this gridview to email after converting to HTML I WANT TO SEND THOSE FILEUPLOAD FILES AS AN ATTACHMENT WITH THIS EMAIL. THE GRIDVIEW WILL BE IN BODY.

Please Help....

Here is the code...

C#
private void emaildatatable()
    {
               
        string body = "<H1 align=center>Change Management System</h1><br>";
        body += "<br><br>";
        string to = ExEMP_PERSONAL.getEmpEmail(Session["empCode"].ToString());
        MyEmail mm = new MyEmail();
       
            body += substring.ToString();
            body += "<br><br>";
            body += "<H3 align=center>Account Closing Request</h3>";
            body += GridViewToHtml(GridView3).ToString();
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                FileUpload fup = GridView1.Rows[i].FindControl("FileUpload1") as FileUpload;
                ArrayList filelist = new ArrayList();
                string dirpath = System.IO.Path.GetDirectoryName(fup.PostedFile.FileName);
                string[] files = Directory.GetFiles(dirpath);
                foreach (string str in files)
                {
                    filelist.Add(System.IO.Path.GetFileName(str));
                }
            mm.sendEmail(to, "", filelist, "Your Request is Submitted for Approval", body);

            }
            
        
    }

and this is my SendEmail method...

C#
public void sendEmail(string to, string cc, ArrayList attachmentfiles, string subject, string body)
    {
        try
        {
            MailMessage mail = new MailMessage();
            foreach (string str in attachmentfiles)
            {
                mail.Attachments.Add(new Attachment(str));
            }
            mail.To.Add(new MailAddress(to.Trim()));
            mail.From = new MailAddress("xyz@abc.com");            
            string messageBody = body;
            mail.Subject = subject;
            mail.Body = messageBody;
            mail.IsBodyHtml = true;
            sendEmail(mail);
        }
        catch (ArgumentException)
        {

        }

    }


Conclusion:

As there are Max 6 fileuploaders... i want to save these files when selected from fileupload into ARRAYLIST as in the method of mm.sendEmail => filelist is an Arraylist Parameter...

Waiting for the best....
Thanks
Posted
Updated 12-May-14 1:13am
v2

1 solution

why don't you use attached file property for detail follow the link
http://stackoverflow.com/questions/13553242/how-to-attach-multiple-files-to-the-email[^]





for file uploader why you use gridview actually am not understand your problem
will you plz explain in detail what you want to do ?
 
Share this answer
 
Comments
AR547 24-Sep-13 6:40am    
Done !!... Actually I was seeking for one method only.... fileuploader in gridview is the requirement of our application as for each request generated in gridview the fileuploader should save its name regarding its task no....

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