Search  


Q&A: How do I delete a file that is lock by another process in C# 
Tuesday, April 21, 2020, 10:34 PM
Posted by Administrator
#edutech #college #work #NFT #education #remotework #onlinelearning #stem #talent #diversity #highered #STEM #blog

Q: I'm looking for a way to delete a file which is locked by another process using C#. I suspect the method must be able to find which process is locking the file (perhaps by tracking the handles, although I'm not sure how to do this in C#) then close that process before being able to complete the file delete using File.Delete().

A: Killing other processes is not a healthy thing to do. If your scenario involves something like uninstallation, you could use the MoveFileEx API function to mark the file for deletion upon next reboot.

If it appears that you really need to delete a file in use by another process, I'd recommend re-considering the actual problem before considering any solutions.
1 comment ( 126 views )   |  permalink   |  $star_image$star_image$star_image$star_image$star_image ( 3 / 476 )

<<First <Back | 1114 | 1115 | 1116 | 1117 | 1118 | 1119 | 1120 | 1121 | 1122 | 1123 | Next> Last>>







Share CertificationPoint & Stay Informed Socially About EduTech?