string savePath = Server.MapPath("\\Upload_File\\"); // Get the name of the file to upload. string fileName = email_attach.FileName; string pathToCheck = savePath + fileName;
email_attach.SaveAs(pathToCheck); string file = pathToCheck; Attachment data = new Attachment(file); mail.Attachments.Add(data); SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("email.testitbd@gmail.com", "1234ASDF"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); email_attach.Dispose(); FileInfo file_Delete = new FileInfo(pathToCheck); if (file_Delete.Exists) { file_Delete.GetAccessControl(); file_Delete.Delete(); }
An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code Additional information: The process cannot access the file 'C:\Users\User\Documents\Visual Studio 2013\WebSites\Email_Sent_Web\Upload_File\DMP.edx' because it is being used by another process.
SmtpServer.Send(mail); data.Dispose(); data = null; email_attach.Dispose(); email_attach = null;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)