I am having a very strange issue right now. I am attempting to get the files of a directory by using this code:
public static string[] fileList = Directory.GetFiles(@File.ReadAllText(Settings.localdir.Trim()));
However, when I do this, I get this error:
Access to the path 'C:\Users\lazho\Desktop' is denied.
But when I do this code:
public static string[] fileList = Directory.GetFiles(@"C:\Users\lazho\Desktop");
It works without any errors. I have no idea why one would throw an error when they both equal the same value. Any Ideas?
PS I have already tried this:
public static string dir = @File.ReadAllText(Settings.localdir.Trim());
public static string[] fileList = Directory.GetFiles(dir);
Your SecurityException
is from File.ReadAllText
method. you can not read drive C
without permission.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.