Click here to Skip to main content
15,882,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my WPF MVVM application,I have a XML file to modify. It is successfully working In Visual Studio. But Its not working, while running the installed application. How can i set the Permissions Through code..

me used this code ,
// current security settings. FileSecurity fSecurity = File.GetAccessControl(FilePath);

        // Add the FileSystemAccessRule to the security settings.
        fSecurity.AddAccessRule(new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name,
            FileSystemRights.FullControl, AccessControlType.Allow));

        // Set the new access settings.
        File.SetAccessControl(FilePath, fSecurity);

Still cant solve the Problem...,

Thanks in advance..
Updated 9-Aug-11 20:30pm

1 solution

You may have to set the InheritanceFlags as well.

DirectorySecurity dirsec = null;
DirectoryInfo dir = new DirectoryInfo(@"C:\temp");
String identity = "SomeUsername";

dirsec = dir.GetAccessControl(AccessControlSections.Access);

rule = new FileSystemAccessRule(identity, FileSystemRights.FullControl | FileSystemRights.Synchronize, AccessControlType.Allow);


rule = new FileSystemAccessRule(identity, FileSystemRights.FullControl | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);



Also ensure that the user/account running the application has the privileges to set access control.
If you get an exception, feel free to post it :-)

I hope that helps...
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900