I tried the same code it's working fine. Please see folder permission.
DirectoryInfo dr = new DirectoryInfo(Server.MapPath("TempPDF"));
try
{
FileInfo[] files = dr.GetFiles();
for (int i = 0; i < files.Length; i++)
files[i].Delete();
}
catch (Exception ex) {
}