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. Application common data with write permission to all user

Application common data with write permission to all user

Scheduled Pinned Locked Moved C#
csharpquestionworkspace
7 Posts 2 Posters 9 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.
  • M Offline
    M Offline
    Maddie from Dartford
    wrote on last edited by
    #1

    Hello, I am writing C# desktop appplication and I want to store some application specific data which should be accessible to all user with write permission. I am using Environment.SpecialFolder.CommonApplicationData for setting location to write file but I found that the file created in my login is not editable by other user. Where should I create the file so that it shoul be accessible to all user with write permission? Regards, Gajesh

    OriginalGriffO 1 Reply Last reply
    0
    • M Maddie from Dartford

      Hello, I am writing C# desktop appplication and I want to store some application specific data which should be accessible to all user with write permission. I am using Environment.SpecialFolder.CommonApplicationData for setting location to write file but I found that the file created in my login is not editable by other user. Where should I create the file so that it shoul be accessible to all user with write permission? Regards, Gajesh

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      If you have created the file when you logged in, then the most likely reason it is not accessible to all users is that it is still in use. It will remain in use once you create it until it is disposed. You can try wrapping you access code in "using" blocks, but I suspect you are always going to get problems of file in use if you try to have multiple users capable of writing to it. Have you considered using a database instead? You may get less problems.

      All those who believe in psycho kinesis, raise my hand.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      M 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        If you have created the file when you logged in, then the most likely reason it is not accessible to all users is that it is still in use. It will remain in use once you create it until it is disposed. You can try wrapping you access code in "using" blocks, but I suspect you are always going to get problems of file in use if you try to have multiple users capable of writing to it. Have you considered using a database instead? You may get less problems.

        All those who believe in psycho kinesis, raise my hand.

        M Offline
        M Offline
        Maddie from Dartford
        wrote on last edited by
        #3

        Thanks a lot for reply. In our application, an XML File is generated when user wants to save some application data from given menu option. These data can be read back to display the information by any logged user. Now, other user should be able to modify the data and save it back. At a time only one user is editing so I think the problem is with the access right (Exception says the same thing: access denied). Regards, Gajesh

        OriginalGriffO 1 Reply Last reply
        0
        • M Maddie from Dartford

          Thanks a lot for reply. In our application, an XML File is generated when user wants to save some application data from given menu option. These data can be read back to display the information by any logged user. Now, other user should be able to modify the data and save it back. At a time only one user is editing so I think the problem is with the access right (Exception says the same thing: access denied). Regards, Gajesh

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          It doesn't have to be the access permissions - though it is worth checking that your users have the correct access rights to the folder. Have you tried setting it to a shared folder with universal read/write permissions? The other possibility is that the file is still in use - you will get an access denied for this as well as for incorrect permissions. If you do not dispose of your File object, it may not be destroyed for some considerable time, and during this period it can be in use even if you have closed it. Ensure that all your file access code - including your users - is safely within "using" blocks and you should be ok. Even then, you will probably have to try...catch...wait...retry a few times for safety if you have multiple users writing to a file. I would still be considering a database rather than an XML file!

          All those who believe in psycho kinesis, raise my hand.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          M 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            It doesn't have to be the access permissions - though it is worth checking that your users have the correct access rights to the folder. Have you tried setting it to a shared folder with universal read/write permissions? The other possibility is that the file is still in use - you will get an access denied for this as well as for incorrect permissions. If you do not dispose of your File object, it may not be destroyed for some considerable time, and during this period it can be in use even if you have closed it. Ensure that all your file access code - including your users - is safely within "using" blocks and you should be ok. Even then, you will probably have to try...catch...wait...retry a few times for safety if you have multiple users writing to a file. I would still be considering a database rather than an XML file!

            All those who believe in psycho kinesis, raise my hand.

            M Offline
            M Offline
            Maddie from Dartford
            wrote on last edited by
            #5

            Thanks. I think it is problem of access permission only. Whenever you create any folder, other user has read only permissions for that folders. So if any other user(from same domain) tries to modify the folder or file within it, it says Access denied. I am trying to create a folder programatically with full control to all user.... How to do it? Any kind of direction will be great help. Also, Let me know if i am wrong or need to take some different approach.

            OriginalGriffO 1 Reply Last reply
            0
            • M Maddie from Dartford

              Thanks. I think it is problem of access permission only. Whenever you create any folder, other user has read only permissions for that folders. So if any other user(from same domain) tries to modify the folder or file within it, it says Access denied. I am trying to create a folder programatically with full control to all user.... How to do it? Any kind of direction will be great help. Also, Let me know if i am wrong or need to take some different approach.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              I haven't tried it myself, but look at this.[^]

              All those who believe in psycho kinesis, raise my hand.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              M 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                I haven't tried it myself, but look at this.[^]

                All those who believe in psycho kinesis, raise my hand.

                M Offline
                M Offline
                Maddie from Dartford
                wrote on last edited by
                #7

                This is what i did and works for me.

                bool isModified = false;
                DirectoryInfo myDirectoryInfo = new DirectoryInfo("FolderPath");
                DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();

                AccessRule rule = new FileSystemAccessRule("Users",
                FileSystemRights.Write |
                FileSystemRights.ReadAndExecute |
                FileSystemRights.Modify,
                InheritanceFlags.ContainerInherit |
                InheritanceFlags.ObjectInherit,
                PropagationFlags.InheritOnly,
                AccessControlType.Allow);

                myDirectorySecurity .ModifyAccessRule(AccessControlModification.Add, rule, out isModified);
                myDirectoryInfo .SetAccessControl(myDirectorySecurity );

                Thanks to all.

                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