Hi all,
This is Hari,
In my application I need to generate a report for different people and send it through mail as attachment, and my approach to this task is I will generate a report for single person ,And send it to his Mail ID and then I will delete the report and generates next person’s report and send it.
To send the report I am using SMTP server. I am able to send the mails if all the mail ids are correct, if the mail id of a person is incorrect in between I am able to handle the exception but I am not able to delete the report of that person the error I am getting is "Internal system error. Access to the path.... is denied."Even I am not able to delete the file manually .How can I come out of this please help me.
----------------------
Thank
[email protected]
Loading
GaneshPosted Feb 5, 2007, 4:04 PM
Whenever a thread occupies a resource, it should be freed once the task is complete. In your case, once the SMTP object sends the report, the physical report on your harddisk should be freed. I guess, this resource is still blocked by SMTP object
//Begin contextMy suggestion is, when you send the mail, use "using" directive, in order to make sure, the resource is forced to free
using(SMTPMail objMail = new SMTPMail)
{
........your code......
objMail.send()
}
After the closing braces, the thread is forced to leave the resource.
I hope this should work. I had a similar problem when reading and deleting a text file and I followed the above approach and it started working
Make sure, whenever you access server objects, you are impersonating yourself
//Impersonate the windows user
System.Security.Principal.
WindowsImpersonationContext impersonationContext;impersonationContext =
(System.Security.Principal.
WindowsIdentity.GetCurrent()).Impersonate();/*include all your code */
//remove impersonation contextusing(SMTPMail objMail = new SMTPMail)
{
........your code......
objMail.send()
}
impersonationContext.Undo();