发送它作为attachement后文件被锁定 [英] File locked after sending it as attachement
本文介绍了发送它作为attachement后文件被锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我送一个文件作为attachement: -
I am sending a file as an attachement :-
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(filePath, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(filePath);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(filePath);
disposition.ReadDate = System.IO.File.GetLastAccessTime(filePath);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
然后我想将文件移动到其他文件夹,但是当我尝试这样做
And then I want to move the file to another folder, however when I try to do this
try
{
//File.Open(oldFullPath, FileMode.Open, FileAccess.ReadWrite,FileShare.ReadWrite);
File.Move(oldFullPath, newFullPath);
}
catch (Exception ex)
{
}
及其投掷该文件已经被另一过程中所使用的异常。谁能帮助我,告诉我怎样才能解开这个文件,以便它可以移动到这个位置?
Its throwing an exception that the file is already being used in another process. Can anyone help me out and tell me how I can unlock this file so that it can be moved to this location?
感谢您的帮助和时间
推荐答案
您的处置的消息
将解决这个问题你。尝试调用的Dispose
您的邮件移动文件,像这样前:
Disposing your message
will fix this for you. Try calling Dispose
on your message before moving the file, like so:
message.Dispose();
File.Move(...)
当MAILMESSAGE处置,所有的锁和资源释放。
When disposing MailMessage, all locks and resources are released.
这篇关于发送它作为attachement后文件被锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文