问题
I want to read some text files with extensions of .txt, .rtf and .log from a nas in my uwp app.
I have followed the instructions on this link, but there is still a "network access denied" error.
This is my Package.appxmanifest file.
EDIT
- I use a
FolderPicker
to let the user choose the folder containing the log files, then I add that folder toFutureAccessList
with a token. - I use the token in 1. to retrieve the folder, then read all the files in it.
Here is the relevant code.
public async static void locateLogsFolder() { var folderPicker = new FolderPicker(); folderPicker.FileTypeFilter.Add("*"); folderPicker.SuggestedStartLocation = PickerLocationId.ComputerFolder; IStorageFolder folder = await folderPicker.PickSingleFolderAsync(); if (folder != null) { // Add to MRU with metadata (For example, a string that represents the date) string mruToken = StorageApplicationPermissions.MostRecentlyUsedList.Add(folder); // Add to FA without metadata string faToken = StorageApplicationPermissions.FutureAccessList.Add(folder); // To open this worksheet file later ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; localSettings.Values[logsFolderKey] = faToken; loadData(); } else { // The file picker was dismissed with no file selected to save } }
2.
private static async Task<bool> loadLogFiles() { ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; if (localSettings.Values.ContainsKey(logsFolderKey)) { string logsFolderPath = localSettings.Values[logsFolderKey].ToString(); IStorageFolder logsFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(logsFolderPath); logFiles = await logsFolder.GetFilesAsync(); return true; } else { string message = "Logs folder has not been loaded successfully. \n" + "Please locate the logs folder via the button on the upper left corner."; Utils.showMessage(message); return false; } }
Besides, I can get the names of the log files, and when I want to read the contents of them, the error network access denied
occurred.
NAS device information: QNAP TS-231P
Any suggestions are welcome, and I can surely provide more details if needed.
Besides, I am looking for a free nas server that I can upload an small sample to test my app, but I fail to find one. I would like to know where I can find it. I am also not sure whether I can ask this on stackoverflow. If it is inappropriate, please direct me where I can post it instead, thanks.
来源:https://stackoverflow.com/questions/46107831/uwp-nas-network-access-denied