cothedo Posted December 11, 2007 Share Posted December 11, 2007 I have helped build a basic content management system where you can upload and delete files. There is a special page where you can view and delete a file by clicking a button. The event of the button is:System.IO.File.Delete(Server.MapPath(...filename...))However, I get an error message saying "The porcess cannot acces the file (...filename & path...) because it is being used by another process."I just don't understand why I get this error to delete a jpg file. I have the rights to the directory the file is deleted from.Any help is appreciated. Link to comment Share on other sites More sharing options...
cothedo Posted January 15, 2008 Author Share Posted January 15, 2008 Well, I found the answer, and for anyone interested, I'll just post it here. My code was right, but what was needed was something called "Garbage Control". After the file has been used or called for in the code behind, use the following code:GC.Collect()That will release the hold on the file and thus make it available again. I have helped build a basic content management system where you can upload and delete files. There is a special page where you can view and delete a file by clicking a button. The event of the button is:System.IO.File.Delete(Server.MapPath(...filename...))However, I get an error message saying "The porcess cannot acces the file (...filename & path...) because it is being used by another process."I just don't understand why I get this error to delete a jpg file. I have the rights to the directory the file is deleted from.Any help is appreciated. Link to comment Share on other sites More sharing options...
aspnetguy Posted January 15, 2008 Share Posted January 15, 2008 It ould be better to store the file object like and then dispose of the object instead of calling the GC which is harder on performance FileStream fs = System.IO.File.Delete(Server.MapPath(...filename...));fs.Close();fs.Dispose(); Link to comment Share on other sites More sharing options...
cothedo Posted January 15, 2008 Author Share Posted January 15, 2008 It ould be better to store the file object like and then dispose of the object instead of calling the GC which is harder on performanceFileStream fs = System.IO.File.Delete(Server.MapPath(...filename...));fs.Close();fs.Dispose(); Thank you, I'll see if I can get this to work Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.