Sunday, September 28, 2014

How to Programmatically allow File Write Access to folder from application?


Hello Synthologic,


I am not aware of any API that can do that. Especially that folder is a file share on network location. I searched around and find this article:


Programmatically Configuring Permissions on a Share


http://ift.tt/1DLvxtp


and also c# set Directory sharing permission Full control for Everyone programmatically


http://ift.tt/1bjcjta


However they are all for setting it on your local PC for others. For remote, in my point of view, client who need to access the location should have the permission first.


So @Synthologic have you considered some other alternative ways? For example, you may do the following:


1. Do not make users know where you put your files in a easy way. Store file location is database or something eles


2. For the permissions, set a permission in your app, alow only you as the administrator of your application to see the logs.


Best regards,






Barry

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

Click HERE to participate the survey.





Hello Barry:


I tried this but unfortunately it only works when I run it.




using System.Security.AccessControl;
using System.Management;
using System.Management.Instrumentation;



DirectoryInfo myDirectoryInfo = new DirectoryInfo(@"I:\Test");
DirectorySecurity myDirectorySecurity =
myDirectoryInfo.GetAccessControl();
myDirectorySecurity.AddAccessRule(new
FileSystemAccessRule(@"UserNameHere",FileSystemRights.Write,
AccessControlType.Allow));
myDirectoryInfo.SetAccessControl(myDirectorySecurity);



The problem is this does not work when the user runs it.



Get error, SystemInvalidOperationException, Method failed with unexpected error code:



I may simply put the errors in a DB, though this would work.



No comments:

Post a Comment