Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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();
                 }



when i did this it throws exception like
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.


how i solve plz help ,thanks in Advance
Posted
Updated 31-Jan-14 19:03pm
v2

1 solution

Dispose the dependecy objects as well

C#
SmtpServer.Send(mail);
           data.Dispose();
           data = null;
           email_attach.Dispose();
           email_attach = null;
 
Share this answer
 
Comments
Kawshik_itbd 1-Feb-14 1:27am    
Thanks KARTHIK :)
Karthik_Mahalingam 1-Feb-14 11:28am    
if this helps, pls mark it as answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900