该文件无法删除,因为它已被另一个进程使用 [英] the file can't be deleted because it's used by another process

查看:63
本文介绍了该文件无法删除,因为它已被另一个进程使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件存储在sql数据库中
&我需要通过电子邮件以附件形式发送这些文件
所以我在特定的文件夹上创建此文件
然后我以电子邮件附件的形式发送
当我尝试在发送电子邮件后删除那些文件时
我有这个错误

该文件无法删除,因为它已被另一个进程使用

所以我该如何从使用中删除那些文件
要删除
关于问候

i have files stored in sql database
& i need to send those files throught email as attachment
so i create this file on specific folder
then i send as attachment with email
when i try to delete those files after sending emails
i have this is error

the file can''t be deleted because it''s used by another process

so how i can remove those files from being used
to be deleted
with regards

推荐答案

所以您可能有类似以下代码的代码

So you probably have code that looks something like this

try
{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    mail.From = new MailAddress("your_email_address@gmail.com");
    mail.To.Add("to_address");
    mail.Subject = "Test Mail - 1";
    mail.Body = "mail with attachment";

    System.Net.Mail.Attachment attachment;
    attachment = new System.Net.Mail.Attachment("you attachment file");
    mail.Attachments.Add(attachment);

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);
    MessageBox.Show("mail Send");
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}



邮件发送后



after the message is sent

SmtpServer.Send(mail);



您需要致电



you need to call

attachment.Dispose();


释放文件以便删除.

希望对您有所帮助.


to free the file up for deleting.

Hope this helps.


如果没有代码,我们如何为您提供确切的解决方案,请从下面的线程中检查可能的情况

文件在之后被另一个进程使用 [ ^ ]
Cant访问文件,因为它正被另一个使用进程 [ ^ ]
With out code how can we give you exact solution, check the possible case from the below threads

File being used by another process after[^]
Cant Access File because it is being used by another process[^]


这篇关于该文件无法删除,因为它已被另一个进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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