该进程无法访问该文件,因为该文件正在被另一个进程使用
我有一个 asp.net 网站,我已经准备好了 .Dispose() 这里是我的代码如下;
尝试一下 {
MailMessage newMail = new MailMessage(MailFrom, MailTo,
邮件主题、邮件消息);
if (MailAttachment != "") { 附件数据 = 新附件(MailAttachment,
MediaTypeNames.Application.Octet); newMail.Attachments.Add(数据); } newMail.BodyEncoding = System.Text.Encoding.UTF8; newMail.IsBodyHtml = true;
SmtpClient 客户端 = new SmtpClient("192.168.2.205"); client.Credentials = CredentialCache.DefaultNetworkCredentials; 客户端.Send(newMail); newMail.Attachments.Dispose(); newMail.Dispose(); 删除附件(邮件附件); lblSuccess.Text = "Başvurunuz alınmıştır teşekkürler."; lblSuccess.Visible = true; 清除表格(); } catch(异常前) { lblSuccess.Text = ex.Message; //lblSuccess.Text = "Bir sorun oluştu bir daha deneyiniz."; lblSuccess.Visible = true; }
但我遇到了同样的错误,它在我的本地主机中运行良好,但在服务器中我遇到了此错误。我该如何修复它?
I have an asp.net website and I allready did .Dispose() here is my code below;
try
{MailMessage newMail = new MailMessage(MailFrom, MailTo,
MailSubject, MailMsg);
if (MailAttachment != "") { Attachment data = new Attachment(MailAttachment,
MediaTypeNames.Application.Octet);
newMail.Attachments.Add(data);
}
newMail.BodyEncoding = System.Text.Encoding.UTF8;
newMail.IsBodyHtml = true;SmtpClient client = new SmtpClient("192.168.2.205"); client.Credentials = CredentialCache.DefaultNetworkCredentials; client.Send(newMail); newMail.Attachments.Dispose(); newMail.Dispose(); DeleteAttachment(MailAttachment); lblSuccess.Text = "Başvurunuz alınmıştır teşekkürler."; lblSuccess.Visible = true; ClearForm(); } catch (Exception ex) { lblSuccess.Text = ex.Message; //lblSuccess.Text = "Bir sorun oluştu bir daha deneyiniz."; lblSuccess.Visible = true; }
But i' m getting the same error, it' s running fine in my localhost but in server i' m getting this error. How can i fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对 Attachment 对象调用 dispose。
在 SmtpClient 上调用 Dispose,不会在附件上调用它。
Call dispose on the Attachment object.
Calling Dispose on the SmtpClient, doesn't call it on the Attachments.