C# Sitecore正在使用计划任务从服务器中删除文件

C# Sitecore正在使用计划任务从服务器中删除文件,c#,sitecore,sitecore7,C#,Sitecore,Sitecore7,在Sitecore中的计划任务中,我想在数据导入后删除一个XML文件。数据导入成功,但删除时出现访问被拒绝异常 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the targe

在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);

            }

确保为运行网站的应用程序池身份用户授予目标文件夹的正确权限。默认情况下,标识为
应用程序池标识
网络服务


另外,请确保包含文件夹不是只读的。是否确定运行应用程序的用户有权删除该位置的文件?是否确定在导入完成后释放文件句柄?是否在运行计划任务时引发此错误?或者您试图在运行它时以其他方式调试它并抛出错误?尝试使用(new Sitecore.SecurityModel.SecurityDisabler()){}@Anton I使用了安全禁用器,但没有成功。但是Sitecore是否以相同的身份将此文件放在该位置?