I am trying to create an accessible (hands-free – neither mouse nor keyboard) replacement for (file) Explorer; NET 7.0; Windows 10 & 11. I am stuck trying to get the list of partitions, folders and files from a NAS. As an example, my NAS has this address: \169.254.8.92
; if I put that into the address bar of File Explorer and press enter the NAS with all of its partition shows up. Thereafter, I can double-click any of the visible partitions to drill down with File Explorer.
Here is some example code:
private bool ListPath(string pFolder = "") {
string directory = pFolder;
try {
sFolderList.Clear();
sFileList.Clear();
if ((string.IsNullOrEmpty(directory)) || !Path.Exists(directory))
directory = @"C:";
sFolderList = Directory.GetDirectories(directory).ToList();
sFileList = Directory.GetFiles(directory).ToList();
sFolderList.Sort();
sFileList.Sort();
addressTextBox.Text = directory;
sCurrentPath = directory;
}
catch (UnauthorizedAccessException) {
TimedMessage("ListCurrentPath – Access Denied to:" +
Environment.NewLine + directory, "ACCESS DENIED");
return false;
}
catch (Exception pException) {
TimedMessage("ListCurrentPath" +
Environment.NewLine + pException.ToString());
return false;
}
return true;
}
The first problem occurs with this statement:
if ((string.IsNullOrEmpty(directory)) || !Path.Exists(directory))
// not working as expected: ^^^^^^^^^^^^^^^^^^^^^^^
directory = @"C:";
Path.Exists() returns false – possibly a permissions issue. However, if I comment that statement out and let the code continue until I get to the statement:
sFolderList = Directory.GetDirectories(directory).ToList();
I get this:
System.IO.IOException: The specified path is invalid. : '\169.254.8.92'
How may I fill these lists?