Hi All,

Thank you for viewing my thread.

I have an enquiry on process. My application runs this way.

First, it will export something to PDF format.
Second, the application will attach the PDF to send an email to someone.
Next, i want to delete the PDF file.

When i execute the application, it indicate that the process is being use and the application fails. I believe the application fails because the PDF file is still used to send email. My question is how do i check if any process is using the PDF. If no process is using the PDF, then i will delete the PDF file.

Let me know if you have doubts on my question.

Thank You!

How are you sending the email? If the objects used to send the email are properly disposed in your code then you should have no problem deleteing the PDF

Hi Fenrir(), thank you for the reply.
I am doing the email like the code below.
how should i dispose?

Attachment data = new Attachment(filepath);
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(filepath);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(filepath);
disposition.ReadDate = System.IO.File.GetLastAccessTime(filepath);
mailMsg.Attachments.Add(data);
smtpClient.Send(mailMsg);

Try disposing the attachment before your delete statement.

data.Dispose();

Thanks Fenrir(), i have got it and managed to delete the file once the PDF is sent. Thanks so much for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.