我有一个发送消息(很多)及其附件的功能。
它基本上遍历目录结构并从文件结构创建电子邮件,例如
c:\emails\message01
\attachments
c:\emails\message02
\attachments
使用标准的 .net c# 来创建消息。
在创建所有消息之后...我有另一个函数可以在之后直接运行,它将消息文件夹复制到另一个位置。
问题是 - 文件被锁定......
注意:我没有移动文件,只是复制它们......
关于如何使用 c# 复制锁定文件的任何建议?
更新
我有这个添加附件的方法
private void AddAttachments(MailMessage mail)
{
string attachmentDirectoryPath = "c:\messages\message1";
DirectoryInfo attachmentDirectory = new DirectoryInfo(attachmentDirectoryPath);
FileInfo[] attachments = attachmentDirectory.GetFiles();
foreach (FileInfo attachment in attachments)
{
mail.Attachments.Add(new Attachment(attachment.FullName));
}
}