[英]Not able to access my system drive folder in UWP application. always return false when i use Directory.Exists
string tallyDirPath = @"D:\Work";
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;
}
正如 Anders 所說,UWP 應用程序正在沙箱中運行。 所以 UWP 應用程序不允許像文件系統一樣直接訪問某些系統資源。 例如,您不能使用使用文件路徑來獲取文件的 .net API。 當然,有些地方是 UWP 應用默認可以訪問的。 更多信息,請查看文件訪問權限
如果您想通過 UWP 應用中的路徑獲取文件。 您必須在清單文件中添加受限的broadFileSystemAccess功能。 此功能適用於Windows.Storage 命名空間中的 API。 這意味着您需要使用帶有文件路徑的 Windows.Storage API,例如StorageFile.GetFileFromPathAsync(String) Method 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.