Application common data with write permission to all user
-
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 -
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, GajeshIf 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.
-
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.
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
-
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
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.
-
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.
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.
-
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.
I haven't tried it myself, but look at this.[^]
All those who believe in psycho kinesis, raise my hand.
-
I haven't tried it myself, but look at this.[^]
All those who believe in psycho kinesis, raise my hand.
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.