Wednesday, April 12, 2017

Sitecore Error: Could not delete candidate folder

This week I ran accross the following error:

ManagedPoolThread #10 09:55:21 INFO  Directory is being deleted by cleanup task: Directory name: E:\_Websites\CMS\cmwebsite\Data\diagnostics\configuration_history\20151211Z.215309Z, directory date: 12/11/2015 4:53:11 PM, age: 156.16:02:09.8430906 (min age: 00:30:00, max age: 30.00:00:00). Reason: Folder is older than max age 30.00:00:00
ManagedPoolThread #10 09:55:21 ERROR Could not delete candidate folder.
Exception: System.UnauthorizedAccessException
Message: Access to the path 'DataFolder.config' is denied.
Source: mscorlib
   at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
   at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
   at Sitecore.Tasks.FileCleaner.GetCandidateFiles(DirectoryInfo folder)

The permission all looked correct and then I came across this knowledge base article. This pointed me to check the advanced permissions on the data folder. What is needed is to set the "Delete subfolders and files" permission on the Data folder.

1. Right click the Data folder and select properties.

2. Go the Security tab and select Advanced.
 

3. Click on the IIS Application Pool user and select Edit.


4. Click on "Show advanced permissions"


5.Check the "Delete subfolders and files" permission.


6. OK your way out, waiting for permission propagation when it comes and you should be good.

If you're still not good, then also make sure the read-only flag is not on. What happens is that Sitecore will keep a copy of any configs that are changed and store them under the diagnostic folder. If the source files have the read-only flag, it will persist when the copy is made. Make sure the App_Config folder and its children don't have the read-only flag.