title: C# DirectorySecurity SetOwner on subcontainers and objects
body: <p>I am trying to change ownership of a windows folder and everything inside it.  Basially I am trying to check the box that would be there if you did this manually in windows that says &quot;Replace owner on subcontainers and objects&quot;.  This will need to work over a network share path.  I am able to get 1 folder deep but then it just stops there.  This does not include the base folder changing either.</p>
  <pre><code> foreach (string directory in Directory.GetDirectories(dirPath))
              {
                  var di = new DirectoryInfo(directory);
                  IdentityReference user = new NTAccount(Login.authUserName.ToString());
                  DirectorySecurity dSecurity = di.GetAccessControl();
                  dSecurity.SetOwner(user);
                  di.SetAccessControl(dSecurity);
              }
  </code></pre>