Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, March 8, 2020 10:22 AM
Hi,
With .net 4.8 winforms i used to check for read/write acces with this:
private static bool HasWriteAccessToFolder(string folderPath)
{
try
{
System.Security.AccessControl.DirectorySecurity ds = Directory.GetAccessControl(folderPath);
return true;
}
catch (UnauthorizedAccessException)
{
return false;
}
}
In .Net Core this doesn´t work anymore. I found this for .net Core:
var ac = new FileInfo(folderPath).GetAccessControl();
when i look into ac i do not see anything like read/write access. So how to check if the user has read and write access to a certain folder?
Greetings, Hans
All replies (3)
Monday, March 9, 2020 2:46 AM ✅Answered
Hi HanseB69,
Thank you for posting here.
I tried this code in .net core.
var ac = new DirectoryInfo (@ "D: \ Test \ f1"). GetAccessControl ();
This requires installing a nuget package: System.IO.FileSystem.AccessControl.
I took a look and it has exactly the same properties and methods as the classe in .net framework and should work for you.
Best Regards,
Timon
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Sunday, March 8, 2020 12:39 PM
Hello,
I would recommend reporting this in Visual Studio with the report an issue icon in the IDE since this worked with 4.8 and not .NET Core. Also make sure you are using the latest release.
Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
NuGet BaseConnectionLibrary for database connections.
Thursday, March 19, 2020 8:11 AM
Hi,
Has your issue been resolved?
If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.
Best Regards,
Timon
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].