Access to the path is denied -when trying to delete files
-
Hi All string FilePath = strphysicalpath + @"Documents\TempReports"; DirectoryInfo di = new DirectoryInfo(FilePath); di.Attributes = FileAttributes.Normal; foreach (string fileName in System.IO.Directory.GetFiles(FilePath)) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); fileInfo.Attributes = FileAttributes.Normal; } string[] filePaths = Directory.GetFiles(FilePath); foreach (string filePath in filePaths) { File.Delete(filePath); } I use this code to delete all my files in the Folder, but I am getting "Access to the path is denied" Please help.
Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com
-
Hi All string FilePath = strphysicalpath + @"Documents\TempReports"; DirectoryInfo di = new DirectoryInfo(FilePath); di.Attributes = FileAttributes.Normal; foreach (string fileName in System.IO.Directory.GetFiles(FilePath)) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); fileInfo.Attributes = FileAttributes.Normal; } string[] filePaths = Directory.GetFiles(FilePath); foreach (string filePath in filePaths) { File.Delete(filePath); } I use this code to delete all my files in the Folder, but I am getting "Access to the path is denied" Please help.
Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com
-
Hi All string FilePath = strphysicalpath + @"Documents\TempReports"; DirectoryInfo di = new DirectoryInfo(FilePath); di.Attributes = FileAttributes.Normal; foreach (string fileName in System.IO.Directory.GetFiles(FilePath)) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); fileInfo.Attributes = FileAttributes.Normal; } string[] filePaths = Directory.GetFiles(FilePath); foreach (string filePath in filePaths) { File.Delete(filePath); } I use this code to delete all my files in the Folder, but I am getting "Access to the path is denied" Please help.
Ramkumar ("When you build bridges you can keep crossing them. ") http://ramkumarishere.blogspot.com
Always wrap your code in "Pre" tag, because it will give better readability and accessibility.