// (1) create test file and delete it again File.Create(Path.Combine(folder, "testfile.empty")); File.Delete(Path.Combine(folder, "testfile.empty")); The last line throws an exception: The process cannot access the file '\\MYPC\C$_AS\RSC\testfile.empty' because it is being used by another process. Why is that?
4 Réponses :
fichier.create code> remonte à un flux, que vous n'avez pas fermé. using(File.Create(path)) {}
File.Delete(path);
Lorsque vous avez créé le fichier, vous l'utilisez jusqu'à ce que vous le fermiez - vous ne l'avez pas fait, d'où l'erreur.
Pour fermer le fichier, vous devez envelopper la création dans un en utilisant Code> Déclaration: P> using(var file = File.Create(Path.Combine(folder, "testfile.empty")))
{
}
File.Delete(Path.Combine(folder, "testfile.empty"));
Essayez ..
File.Create(Path.Combine(folder, "testfile.empty")).Dispose(); File.Delete(Path.Combine(folder, "testfile.empty"));
Créer code> La méthode renvoie un filtream qui doit être proche avant de faire d'autres opérations: