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:
string FilePath = uploadFile.PostedFile.FileName;
string filenameadding = uploadFile.FileName.ToString(); ;
DataTable dt1 = new DataTable();
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:
mail.ReplyTo = new MailAddress(emailaddr);
mail.Priority = MailPriority.Normal;
if (uploadFile.PostedFile != null)
{
if (grdfiledetails.Rows.Count > 0)
{
for(int i=0;i<grdfiledetails.Rows.Count;i++)
{
string strFileName = Path.GetFileName(uploadFile.PostedFile.FileName);
}
}
else
{
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