发送带有从文件上传控件中选择的多个附件的邮件 [英] sending mail with multiple attchments selected from file upload control

查看:97
本文介绍了发送带有从文件上传控件中选择的多个附件的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的网络应用程序中我需要发送带有附件的邮件,这些附件来自

fileupload控件但需要添加多个附件。



i占用了一个网格,并且我添加了网格,但问题是如果我选择单个文件我能够发送邮件,

但如果我选择了多个文件我无法发送邮件..请帮助



我的代码如下:




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();//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:

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

推荐答案

参考参考



发送邮件 [ ^ ]



发送邮件 - 2 [ ^ ]
see reference

Send Mail[^]

Send Mail - 2[^]


请参阅以下链接: -

http://social.msdn.microsoft.com/Forums/vstudio/en-US/9d1a22d4-4355-455a-8f57-072bb2a5d7c0/how-to-send-email-with-multiple-attachments -in-c?forum = csharpgeneral [ ^ ]

http://stackoverflow.com/questions/1457940/multiple-attachment-file-in- email-using-c-sharp [ ^ ]

http://www.aspsnippets.com/Articles/How-to-send-email-with-Multiple-Attachments-in-ASPNet-Website.aspx [< a href =http:// www。 aspsnippets.com/Articles/How-to-send-email-with-Multiple-Attachments-in-ASPNet-Website.aspx\"target =_ blanktitle =新窗口> ^ ]

带有多个附件的ASP.NET电子邮件 [ ^ ]

这可以帮助你
refer below links:-
http://social.msdn.microsoft.com/Forums/vstudio/en-US/9d1a22d4-4355-455a-8f57-072bb2a5d7c0/how-to-send-email-with-multiple-attachments-in-c?forum=csharpgeneral[^]
http://stackoverflow.com/questions/1457940/multiple-attachment-file-in-email-using-c-sharp[^]
http://www.aspsnippets.com/Articles/How-to-send-email-with-Multiple-Attachments-in-ASPNet-Website.aspx[^]
ASP.NET email with multiple attachments[^]
this may help you


这篇关于发送带有从文件上传控件中选择的多个附件的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆