Sitecore 使用计划任务从服务器删除文件

Sitecore deleting a file from the server with Schedule Tasks

在 Sitecore 的计划任务中,我想在数据导入后删除一个 XML 文件。数据导入成功,但删除时出现拒绝访问异常。

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->
System.UnauthorizedAccessException: Access to the path 'X:\..\Website\temp\import\data.xml' is denied. at 
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at
System.IO.File.InternalDelete(String path, Boolean checkHost) at Website.Intranet.Kernel.ScheduledTasks.Scheduler.ImportData()

这是我用来删除文件的代码。

if (File.Exists(filePath))
            {
                File.SetAttributes(filePath, FileAttributes.Normal);
                File.Delete(filePath);

            }

确保为 应用程序池 身份用户授予对目标文件夹的正确权限,您的网站 运行 位于该用户名下。默认情况下,身份是 Application Pool IdentityNetworkService.

还要确保包含文件夹不是 只读