在我的網站上,用戶從他的系統上傳一些文件併發送電子郵件。如何在asp.net C#中發送電子郵件後刪除附件?
try
{
if(Request.Files!=null)
{
//save the file to some temp location
//Attach the file to email & send
}
}
catch(Exception ex)
{
//log exception
}
finally
{
//delete the file from temp location
System.IO.File.Delete(attachmentLocation);
}
但是,如果電子郵件sendings失敗,那麼我可以刪除該文件,但如果郵件成功發送,然後我得到一個異常
文件檢驗.pdf不能被刪除,因爲它由另一個進程使用
是否可以附加文件而不保存它?
如果不是,那麼在發送電子郵件後如何刪除文件?
供參考: - 這是一個AJAX調用。
的問題是不你顯示的代碼。顯示電子郵件發送和文件刪除代碼。 – CodeCaster
finally {System.IO.File.Delete(attachmentLocation);} – abc
請修改代碼添加到您的文章 - 通常很難閱讀評論 –