本文介绍了文件上载在Safari浏览器中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个asp.net页面用于发送文件作为附件。 我正在使用文件上传控件选择多个文件并将其保存在一个文件夹中并从该文件夹中将该文件作为附件发送给邮件。 这样工作正常在谷歌浏览器和IE浏览器上,但Safari浏览器文件正在以0字节大小复制。如果我们选择1个单个文件作为附件,那么它在所有浏览器中都能正常工作。 提前致谢。 发送代码按钮 使用(MailMessage) mailMessage = new MailMessage()) { mailMessage.From = new MailAddress ( [email protected]); mailMessage.Subject = txtSubject.Text.Trim(); mailMessage.Body = txtMessage.Text.Trim(); mailMessage.IsBodyHtml = true ; mailMessage.To.Add( new MailAddress(txtTo.Text.Trim())); // 将所有选择的文件复制到EmailFiles文件夹以便发送为邮件的附件。 if (FileUpload1.HasFile || FileUpload1.FileName!= ) { foreach (HttpPostedFile uploadedFile in FileUpload1.PostedFiles) { uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath( 〜/ EmailFiles /),uploadedFile.FileName)); } } // 加密文件 string encryptFilePath = Request.PhysicalApplicationPath + EmailFiles\\; string [] S2 = Directory.GetFiles(encryptFilePath); foreach (字符串 fileName in S2) { encryptFiles(fileName); } // 循环遍历所有文件以将文件作为附件发送。 string UplodedfilesForEmail = Request.PhysicalApplicationPath + EmailFiles\\; string [] S1 = Directory.GetFiles(UplodedfilesForEmail); foreach (字符串 fileName in S1) { mailMessage.Attachments.Add( new Attachment(fileName)); } SmtpClient smtp = new SmtpClient(); smtp.Host = mail.domain.com; smtp.EnableSsl = true ; System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential( emailID, < password>); NetworkCred.UserName = mailMessage.From.Address; NetworkCred.Password = < password>; smtp.UseDefaultCredentials = true ; smtp.Credentials = NetworkCred; ServicePointManager.ServerCertificateValidationCallback = delegate ( object s,X509Certificate certificate,X509Chain chain,SslPolicyErrors sslPolicyErrors) {返回 true ; }; smtp.Port = 25 ; smtp.Send(mailMessage); } 解决方案 读一读这个 http://stackoverflow.com/questions/15766644/any-workarounds-for-the-safari-html5-multiple-file-upload-bug [ ^ ] I have one asp.net page for sending files as an attachment.I am selecting multiple files using file upload control and saving it in one folder and from that folder i m sending that files as an attachment with a mail.This is working fine on google chrome and IE but on "Safari" browser files are getting copied with "0" byte size. If we are selected 1 single file as an attachment then its working fine in all the browsers.Thanks in advance.Code of Send Buttonusing (MailMessage mailMessage = new MailMessage()) { mailMessage.From = new MailAddress("[email protected]"); mailMessage.Subject = txtSubject.Text.Trim(); mailMessage.Body = txtMessage.Text.Trim(); mailMessage.IsBodyHtml = true; mailMessage.To.Add(new MailAddress(txtTo.Text.Trim())); // Copy all seleted files to "EmailFiles" folder for sending as an attachment to mail. if (FileUpload1.HasFile || FileUpload1.FileName !="") { foreach (HttpPostedFile uploadedFile in FileUpload1.PostedFiles) { uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/EmailFiles/"), uploadedFile.FileName)); } } // Encrypt files string encryptFilePath = Request.PhysicalApplicationPath + "EmailFiles\\"; string[] S2 = Directory.GetFiles(encryptFilePath); foreach (string fileName in S2) { encryptFiles(fileName); } // looping through all the files to send files as an attachment. string UplodedfilesForEmail = Request.PhysicalApplicationPath + "EmailFiles\\"; string[] S1 = Directory.GetFiles(UplodedfilesForEmail); foreach (string fileName in S1) { mailMessage.Attachments.Add(new Attachment(fileName)); } SmtpClient smtp = new SmtpClient(); smtp.Host = "mail.domain.com"; smtp.EnableSsl = true; System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential("emailID", "<password>"); NetworkCred.UserName = mailMessage.From.Address; NetworkCred.Password = "<password>"; smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; smtp.Port = 25; smtp.Send(mailMessage); } 解决方案 这篇关于文件上载在Safari浏览器中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 21:08