Modify permissions to a Directory or Files with Net
With the code below you can copy and set specific permissions to a directory within Net app.
using System.Security.AccessControl;
using System.Security.Principal;
string sourceFolder = ConfigurationManager.AppSettings["sourceFolder"];
string newFolder = ConfigurationManager.AppSettings["newFolder"];
Console.WriteLine($"sourceFolder {sourceFolder}");
string lastFolder = sourceFolder.Split('\\').Last();
newFolder = Path.Combine(newFolder, lastFolder);
Directory.Move(sourceFolder, newFolder);
// Get security settings from the subfolder
DirectoryInfo newDirInfo = new DirectoryInfo(newFolder);
DirectorySecurity newFolderSecurity = newDirInfo.GetAccessControl();
// Enable inheritance on the subfolder
newFolderSecurity.SetAccessRuleProtection(false, false); // False = enable inheritance, True = preserve inherited rules
// Apply the parent's security rules to the subfolder
newDirInfo.SetAccessControl(newFolderSecurity);
Console.WriteLine($"Folder {newFolder} security is updated");

Login as another user in SharePoint 2019 on-premises site in Chrome
Set limited Wi-Fi connection within command line in Windows
A sticker problem with the fan in HP laptop