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. File Permissions

File Permissions

Scheduled Pinned Locked Moved C#
windows-adminjsonhelpquestion
5 Posts 3 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.
  • K Offline
    K Offline
    krisp
    wrote on last edited by
    #1

    Hi all, I would like to be able to determine at the start of my app if the user has enough permissions for many different files/folders. I have read articles that discuss calling Win32 API NTFS calls, and Active Directory calls to get ACLs, but this seems like something that I would think would be inside dot net some how. No? Like something like: if( File.GetPermissions( "C:\\my cars" ) == FileAccess.Read | FileAccess.Write ) { // good } else { MessageBox.Show( "Not enough permissions. ); } Anyone got any ideas? Thanks alot for any help you can lend, Kris.

    L H 2 Replies Last reply
    0
    • K krisp

      Hi all, I would like to be able to determine at the start of my app if the user has enough permissions for many different files/folders. I have read articles that discuss calling Win32 API NTFS calls, and Active Directory calls to get ACLs, but this seems like something that I would think would be inside dot net some how. No? Like something like: if( File.GetPermissions( "C:\\my cars" ) == FileAccess.Read | FileAccess.Write ) { // good } else { MessageBox.Show( "Not enough permissions. ); } Anyone got any ideas? Thanks alot for any help you can lend, Kris.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Krisp, I do not know if this going to help you or not. But System.IO.File.GetAttributes(FileName)returns a file's attributes. Typical Attributes are Archive, ReadOnly and hidden, I am sure there is more. Hope this helps!

      K 1 Reply Last reply
      0
      • L Lost User

        Krisp, I do not know if this going to help you or not. But System.IO.File.GetAttributes(FileName)returns a file's attributes. Typical Attributes are Archive, ReadOnly and hidden, I am sure there is more. Hope this helps!

        K Offline
        K Offline
        krisp
        wrote on last edited by
        #3

        No, that doesn't get any file permissions such as: can the user read/write. I had looked at that myself as well. But thanks anyways.

        L 1 Reply Last reply
        0
        • K krisp

          No, that doesn't get any file permissions such as: can the user read/write. I had looked at that myself as well. But thanks anyways.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Thats ok, I was reading this on an other site. It deals with permissions. http://www.codeguru.com/cs\_misc/Security.html

          1 Reply Last reply
          0
          • K krisp

            Hi all, I would like to be able to determine at the start of my app if the user has enough permissions for many different files/folders. I have read articles that discuss calling Win32 API NTFS calls, and Active Directory calls to get ACLs, but this seems like something that I would think would be inside dot net some how. No? Like something like: if( File.GetPermissions( "C:\\my cars" ) == FileAccess.Read | FileAccess.Write ) { // good } else { MessageBox.Show( "Not enough permissions. ); } Anyone got any ideas? Thanks alot for any help you can lend, Kris.

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            No, there is currently nothing in the .NET base class library that deals with NTFS permissions. There may be some third-party libraries out there and I'm sure "Longhorn" will introduce such encapsulation, but you either have to use the NTFS APIs or try to write a zero-byte file to the directory and catch any exceptions that are thrown. For more discussion about alternatives, please click the "Search Comments" link above. We have covered this in the past. There are also a few articles here on the CP web site. Use the search text box toward the top of the page (below the logo).

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            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