【发布时间】:2014-11-06 03:16:03
【问题描述】:
当我尝试从 WPF 应用程序打开 OneDrive 文件路径时,使用 File.ReadAllText(filename); 时出现以下错误:
The file cannot be accessed by the system.
尽管尝试显式检查读取权限:
private static bool HasReadPermissions(string filename)
{
FileSystemSecurity security = File.GetAccessControl(filename);
var rules = security.GetAccessRules(true, true, typeof(NTAccount));
var currentUser = new WindowsPrincipal(WindowsIdentity.GetCurrent());
foreach (FileSystemAccessRule rule in rules)
{
if (!currentUser.IsInRole(rule.IdentityReference.Value) || (rule.FileSystemRights & (FileSystemRights.ReadData | FileSystemRights.Read)) == 0)
{
continue;
}
if (rule.AccessControlType == AccessControlType.Deny)
{
return false;
}
if (rule.AccessControlType == AccessControlType.Allow)
{
return true;
}
}
return false;
}
是否有任何方法可以检查 OneDrive 权限或检测文件是否为 OneDrive 文件或在 WPF 应用程序中实际打开 OneDrive 文件?我认为这个文件只能在线获得这一事实可能是问题所在;有没有办法检测 WPF 或 Windows 桌面应用程序中的仅在线文件?
【问题讨论】:
-
您能提供一个示例路径吗?
标签: c# .net wpf file-io onedrive