I know that this question has been answered, and it has been almost a year, but for those who are looking for and reading this question, I would like to suggest that you close the file after it is completed, or at least conduct an investigation, for example, mine The answer shows.
I am not a programming specialist, but recently I came across this situation.
I created the WinForms C # program and used File.ReadAllText to copy text to a string. Subsequently, I tried to delete the file directly from the folder, and not through the program, but I received an error message that the file is still open in another program. Then I stopped the program from starting and was able to delete the file.
This is my experience in Visual Studio 2012 Ultimate. Could do something else, but what it did for me.
When I used StreamReader.ReadToEnd , then StreamReader.Close in the same file, I had no problems deleting the file during program startup.
Alaba baju
source share