简体   繁体   English

无法在 UWP 应用程序中访问我的系统驱动器文件夹。 当我使用 Directory.Exists 时总是返回 false

[英]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.

相关问题 Directory.Exists()总是返回false? - Directory.Exists() always returning false? Directory.exists在c#编码中为映射驱动器返回false - Directory.exists returns false for mapped drive in c# coding Directory.Exists(@“\\\\ SERVERIP \\ aFolder \\ bFolder”); 总是返回false - Directory.Exists(@“\\SERVERIP\aFolder\bFolder”); always returns false Directory.Exists 在目录存在时返回 false(适用于独立控制台应用程序,但不适用于 ASP 项目) - Directory.Exists returns false when directory is present (works in a standalone console application but not in an ASP project) 在网络关闭时,在网络文件夹上使用Directory.Exists - Using Directory.Exists on a network folder when the network is down 无法使用UWP应用程序访问系统上的Word文档 - Not able to access the Word Document on my system using the UWP application Directory.Exists和FileSystemWatcher - Directory.Exists and FileSystemWatcher Directory.Exists()无法识别不存在的文件夹(反斜杠错误) - Directory.Exists() fails with to recognize nonexistent folder (backward slash error) 当目录不存在时,Directory.Exists返回true - Directory.Exists returns true when directory is not present System.IO.Directory.Exists 目录存在时返回 false - System.IO.Directory.Exists returns false when directory exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM