문제

Here i need when file uploaded then i need that file attached and mail to it.But attachment file path wrong.

Error : Could not find file 'C:\Program Files (x86)\IIS Express\test.xlsx'. //<--Wrong file path

Code

            for (int i = 0; i < fuUploadedFiles.UploadedFiles.Count; i++)
        {
            if (fuUploadedFiles.UploadedFiles[i] != null)
            {
                fuUploadedFiles.UploadedFiles[i].SaveAs(ServerPath + "\\" + fuUploadedFiles.UploadedFiles[i].FileName);

                using (MailMessage mm = new MailMessage())
                {
                    if (fuUploadedFiles.UploadedFiles.Count != null)
                    {
                        string FileName = fuUploadedFiles.UploadedFiles[i].FileName;
                        mm.Attachments.Add(new Attachment(FileName));//<-- Error generate here
                        SmtpClient smtp = new SmtpClient();
                        smtp.Host = "smtp.gmail.com";
                        smtp.EnableSsl = true;
                        NetworkCredential NetworkCred = new NetworkCredential("myemail@email.com", "mypassword");
                        smtp.UseDefaultCredentials = true;
                        smtp.Credentials = NetworkCred;
                        smtp.Port = 587;
                        smtp.Send(mm);
                    }     
                }
            }
        }
도움이 되었습니까?

해결책

i think you need to use virtual path instead of real path. ATM i think fileName as real path. use result of ServerPath + "\" + fuUploadedFiles.UploadedFiles[i].FileName inplace of fileName. This should solve the issue

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top