Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
i am a developer new to the sector though. i have done a code that sends an converts crystal reports to pdf saves the file at a location in the computer then sends an email attachment linked to the particular file. due to storage i prefer to delete the file immediately after sending but am experiencing a problem as it gives me this error "the action cannot be completed because file is open in another program "
how can i solve this problem please
Posted 8-Nov-13 22:47pm
hiqedme263

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can't, most likely. There are two possible causes:
1) The code you used to write the file in the first place has not properly Closed and Disposed the stream it used for writing - so until the garbage collector gets in, the file will be in used and cannot be deleted. Check you code, and make sure you delete any open streams.
2) It may be that the email server is reading the file and trying to send it. If so, you can't delete it because the email server needs the file content!
 
Even if you could delete the file immediately, it's probably a bad idea - if you delete it and the email system has not finished copying it to the recipient, then there is a good chance that it won;t be available when the message is actually sent, and the email could fail. - this is just a guess - I haven't tried, and your email system may be different from mine anyway. But at the very least, you would need to close and Dispose the Email objects you created before the file would be available for deleting.
  Permalink  
Comments
hiqedme at 9-Nov-13 4:36am
   
thanks this was helpful..alot
OriginalGriff at 9-Nov-13 4:41am
   
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.150302.1 | Last Updated 9 Nov 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100