after email deleting attachment file, error “The process cannot access the file because it is being used by another process.”

前端 未结 7 637
逝去的感伤
逝去的感伤 2021-01-01 23:48

I am doing an email form. Email has attachments and after attaching files email is sent. Next there is requirement to delete file from server. When I tried to get the file i

相关标签:
7条回答
  • 2021-01-02 00:00

    use the below code to fill the imagebox this will solve the problem of deleting the file.

    pictureBox1.Load(filePath);   
    
    0 讨论(0)
  • 2021-01-02 00:01

    After execute "SendMessageGmail", free the attachment of MailMessage.Attachments by iterating.

    SendMessageGmail(oMess);
    if(oMess.Attachments != null) {
      for(Int32 I = oMess.Attachments.Count - 1; I >= 0;I--) {
        oMess.Attachments[i].Dispose();
      }
      oMess.Attachments.Clear();
      oMess.Attachments.Dispose();
    }
    oMess.Dispose();
    oMess = null;
    
    0 讨论(0)
  • 2021-01-02 00:13
    oMess.Dispose()
    

    This worked for me.

    0 讨论(0)
  • 2021-01-02 00:14
    private void SendMessageGmail(MailMessage message)       
    {
        SmtpClient client = new SmtpClient("smtp.gmail.com");
        client.EnableSsl = true;
        client.UseDefaultCredentials = false;
        NetworkCredential loginInfo = new NetworkCredential("myid", "mypassword");
        client.Credentials = loginInfo;
        client.Port = 587;
        client.Send(message);
        oatt.Dispose();
    }
    
    0 讨论(0)
  • 2021-01-02 00:21

    Use this one. It worked for me

    client.Send(oMess);
    oMess.Attachments.Dispose();
    

    I tried this one but it didn`t work for me

    client.Send(oMess);
    oMess.Dispose();
    
    0 讨论(0)
  • 2021-01-02 00:22

    You should try to do oatt.Dispose();

    0 讨论(0)
提交回复
热议问题