Pdf-accessing problem

Hello

I am facing the problem of Pdf-accessing actually i m sending PDF file with attachment after saving this file to that server using below code:
System.Net.Mail.Attachment a = new System.Net.Mail.Attachment(Server.MapPath("PDFChangeGrid.pdf"));
message.Attachments.Add(a);

and i m saving file using this code below:
pdf.Save(Server.MapPath("PDFChangeGrid.pdf"));
it is working fine
this all functioning is happenning on the button click event
as i sent mail first time on button click then mail has sent fine but If again i sent it then problem occurs
"The Process of accessing the file is denied becoz this file is using by another process "

I have tried out to delete that file after sent that pdf and also destroy that attachment variable but this problem occurs on that position because to delete that file first we have to access it so problem consist that time as well.

please tell me right solution for that

Thanks
Nidhi

Hello Nidhi,

Thanks for considering Aspose.

In order to access the PDF document to be sent again or to delete it, first Attachment object must release the resource PDF document. In order to release the resource file, please use the following method.

Attachment.Dispose();

In case it does not resolve your problem or you've any further query, please feel free to contact.