エラーが発生するため、現在コードをデバッグしています。
The process cannot access the file because it is being used by another process.
そして、このコード行でエラーが発生すると思います
foreach (var filename in filenames)
{
var file = Path.Combine(filePath, filename);
mail.Attachments.Add(new Attachment(file));
}
// Send Mail
smtpServer.Send(mail);
DeleteFiles();
この方法でメール送信時にフォルダ内のファイルを削除したい
private void DeleteFiles()
{
string filePath = Server.MapPath("~/Content/attachments");
Array.ForEach(Directory.GetFiles(filePath), System.IO.File.Delete);
}
閉鎖/廃棄について読みましたか?FileStream などですが、コードでそれを使用するにはどうすればよいですか? 前もって感謝します。