在Sitecore中的计划任务中,我想在数据导入后删除XML文件。数据导入成功,但在删除时,我得到拒绝访问异常。Sitecore使用计划任务从服务器删除文件
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);
}
确定运行应用程序,用户必须删除该位置的文件的权利? – Gatogordo
您确定您在导入完成后释放文件句柄吗? –
运行计划任务时是否引发此错误?或者你尝试调试它,而以某种方式运行它并抛出错误?尝试使用(新Sitecore.SecurityModel.SecurityDisabler()){@ – Anton