windows server 2008 r2 - Set Owner of Directory and Sub Containers in C# -
when setting owner of preexisting folder in server 2008 r2, there way make propagate of sub containers under object? can in properties diag, not see switch this.
i looking way avoid recusing through sub containers this.
this code switch owner top level directory.
directoryinfo mydirectoryinfo = new directoryinfo("path here"); directorysecurity mydirectorysecurity = mydirectoryinfo.getaccesscontrol(); system.security.principal.identityreference myowner = new system.security.principal.ntaccount("target owner account"); mydirectorysecurity.setowner(myowner); mydirectoryinfo.setaccesscontrol(mydirectorysecurity);
there no overload provide you.
but following code that:
directoryinfo directoryinfo = new directoryinfo(path); var directories = directoryinfo.enumeratedirectories("*.*", searchoption.alldirectories); foreach (var directory in directories) { // set owner }
note use enumeratedirectories
instead of directory.getdirectories
, return instantly if there 1000's of directories.
Comments
Post a Comment