We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Not able to delete file after attaching as a LinkedResouce


I am trying to attach an image as a linked resource to mail message. I do that using following code:
if (contentId != htmlContentId) continue;
Trace.Main.note(“ContentID found : {}”, contentId);
var img = new LinkedResource(fileNameWithPath,
ContentId = contentId

I want to delete the image file i just attached so i tried this

if (File.Exists(fileName))

But i received exception:
The process cannot access the file ‘E:\TempUploadFolder\1001720459\recordServer.txt’ because it is being used by another process.

I have made sure that i can delete the file when I am not using it as LinkedResource. Why some Aspose process is not allowing me to delete the file? how can I resolve this?

Let me know if you need more explanation.


Hi Jason,

In order to delete the linked resource, you need to dispose it when you are done with all the message manipulation/processing. This will allow to free the resources for deletion.

Sample Code: