在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);
}
答案 0 :(得分:1)
确保为目标文件夹授予运行网站的应用程序池身份用户的正确权限。默认情况下,标识为NetworkService
或.
。
还要确保包含的文件夹不是只读