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...
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...
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