该进程无法访问该文件,因为该文件正在被另一个进程使用

发布于 2024-09-01 01:32:46 字数 1140 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞄了个咪的 2024-09-08 01:32:46

对 Attachment 对象调用 dispose。

在 SmtpClient 上调用 Dispose,不会在附件上调用它。

Call dispose on the Attachment object.

Calling Dispose on the SmtpClient, doesn't call it on the Attachments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文