[英]Not able to access my system drive folder in UWP application. always return false when i use Directory.Exists
string tallyDirPath = @"D:\Work"; string tallyDirPath = @"D:\Work";
if (Directory.Exists(tallyDirPath)) { if (Directory.Exists(tallyDirPath)) {
var watcher = new FileSystemWatcher(tallyDirPath);
watcher.NotifyFilter = NotifyFilters.Attributes
| NotifyFilters.CreationTime
| NotifyFilters.DirectoryName
| NotifyFilters.FileName
| NotifyFilters.LastAccess
| NotifyFilters.LastWrite
| NotifyFilters.Security
| NotifyFilters.Size;
} }
As Anders said, UWP apps are running in the sandbox.正如 Anders 所说,UWP 应用程序正在沙箱中运行。 So UWP apps are not allowed to access some system resources directly like the file system.
所以 UWP 应用程序不允许像文件系统一样直接访问某些系统资源。 For example, you can't use the .net APIs that use the file path to get the file.
例如,您不能使用使用文件路径来获取文件的 .net API。 Of course, there are some places that UWP apps could access by default.
当然,有些地方是 UWP 应用默认可以访问的。 For more information, please check File access permissions
更多信息,请查看文件访问权限
If you want to get a file via a path in UWP apps.如果您想通过 UWP 应用中的路径获取文件。 You have to add the restricted broadFileSystemAccess capability in the manifest file.
您必须在清单文件中添加受限的broadFileSystemAccess功能。 This capability works for APIs in the Windows.Storage namespace .
此功能适用于Windows.Storage 命名空间中的 API。 This means you need to use the Windows.Storage APIs with the file path like StorageFile.GetFileFromPathAsync(String) Method .
这意味着您需要使用带有文件路径的 Windows.Storage API,例如StorageFile.GetFileFromPathAsync(String) Method 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.