Try to delete files used by IIS

Posted by Cédric Boivin on Server Fault See other posts from Server Fault or by Cédric Boivin
Published on 2011-11-11T15:33:00Z Indexed on 2011/11/11 17:58 UTC
Read the original article Hit count: 336

Filed under:
|
|
|
|

I got a service coded in c# whoes deleted somes web site files hosted on iis, before an update. But sometime when i delete the files, they stay there.

If I try to delete them manually, via explorer, the file are not deletable, because they are in state "Delete pending".

There is the way my service try to delete the file

 try
                {
                  // Enlève tout les attributs sur le fichiers afin de s'assurer que le fichier n'est pas en lecture seul
                  File.SetAttributes(file, FileAttributes.Normal);

                  // Supprime le fichier
                  File.Delete(file);
}

It's there a way to avoid this state ?

What can i do to force the delete by c# code?

Could i release all process to the file by c# code ?

The environnement is

IIS 7.5 Windows 2008-r2 .net 4.0

Thanks

© Server Fault or respective owner

Related posts about c#

Related posts about delete