Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Changing the ownership of files and folders

Changing the ownership of files and folders

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lane0p2
    wrote on last edited by
    #1

    Hi, i can use this code to change the ownership of a directory ********************************************* DirectoryInfo dInfo = new DirectoryInfo(folderPath); DirectorySecurity oDirectorySecurity = new DirectorySecurity(); NTAccount owner = new NTAccount("Administrators"); oDirectorySecurity.SetOwner(owner); dInfo.SetAccessControl(oDirectorySecurity); ********************************************* but does anyone know how to make this recursive, so it changes the owner of all the sub files and folders? Many Thanks, Phil

    M 1 Reply Last reply
    0
    • L lane0p2

      Hi, i can use this code to change the ownership of a directory ********************************************* DirectoryInfo dInfo = new DirectoryInfo(folderPath); DirectorySecurity oDirectorySecurity = new DirectorySecurity(); NTAccount owner = new NTAccount("Administrators"); oDirectorySecurity.SetOwner(owner); dInfo.SetAccessControl(oDirectorySecurity); ********************************************* but does anyone know how to make this recursive, so it changes the owner of all the sub files and folders? Many Thanks, Phil

      M Offline
      M Offline
      Mbah Dhaim
      wrote on last edited by
      #2

      use Directory.GetDirectories and Directory.GetFiles instead and do it recursively hope it help

      dhaim programming is a hobby that make some money as side effect :)

      L 1 Reply Last reply
      0
      • M Mbah Dhaim

        use Directory.GetDirectories and Directory.GetFiles instead and do it recursively hope it help

        dhaim programming is a hobby that make some money as side effect :)

        L Offline
        L Offline
        lane0p2
        wrote on last edited by
        #3

        great, thanks. works a treat.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups