I am trying to upload a file .When file is uploaded, I take some information from it and then i want to delete it.
I manage to upload it, save it and get the info from it, but when i try to delete it i get the follwing exception "The process cannot access the file 'C:\Data\UploadedDocuments\81741092055.pdf' because it is being used by another process."
<pre>public async Task<IActionResult> SendMaillNewsLetter(IFormFile file,string subject,string fileName,string message) { tempGuid = Guid.NewGuid(); ContactUs objUserContactUs = new ContactUs(); var fileSavePath = _configuration.RootPath + fileName; if (file.Length > 0) { using (var stream = new FileStream(fileSavePath, FileMode.Create)) { await file.CopyToAsync(stream); } } List<string> NewsletterSubscriptionList = new List<string>(); NewsletterSubscriptionList = _UserModel.GetNewsletterSubscriptionList(NewsletterSubscriptionList); if(NewsletterSubscriptionList.Count>0) { foreach (string item in NewsletterSubscriptionList) { _emailSender.SendEmail(item, "", subject, message, fileSavePath); } if (System.IO.File.Exists(fileSavePath)) { try { System.IO.File.Delete(fileSavePath); } catch (Exception ex) { } } } return Ok(new { objUserContactUs }); }
F-ES Sitecore
var msg = new MailMessage();
msg.Attachments.Dispose();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)