cannot delete image file using File.Delete
I just try a simple method to delete file, File.Delete("path to file") can delete some types of file, but every time I use it to delete an image, it pop an error like "The path is denied/ file is currently in use"
I find it very strange, no process is using that image and in my project, no code makes use of that image, only 1 line File.Delete, so what is that error and how to overcome this ?
One more thing, I saw that error when programming in Vista, then I tried it on XP and the image was deleted smoothly, can anyone explain this
Re: cannot delete image file using File.Delete
Did you check the attribute to make sure the file is not protected? You may need do that or clear the attribute for the file first.
Re: cannot delete image file using File.Delete
Is the image in the program files folder or beneath it ?
Vista restricts access to the program files folder and other folders unless the application is run in administrator mode.
This causes problems with applications which write to their installation folder in program files, or any sub folder of the installation folder.
Instead you should write application files to a sub folder in the folder given by
Code:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Darwen.
Re: cannot delete image file using File.Delete
thanks you 2 and the answers're NO, that image is not protected and is not under Program Files folder, I put it in an ordinary folder and without any attribute (I can delete it using command in Windows context menu but... can not use File.Delete)