Network path is not shared when trying to create folder with sharing everyone using c#

77 Views Asked by At

I have a wpf application in which i try to create folder on client machine and give sharing permission to everyone as i want to transfer crystal reports to those folders (unc network folder).I am able to create the folder with sharing permission showing as everyone with code but when i click the folder properties->sharing .It says network path not shared . enter image description here

enter image description here

I have impersonated an administrator account and created the folder using below code ,i got from a stackoverflow post

private static void GrantAccess(string file)
{

    bool exists = System.IO.Directory.Exists(file);
    if (!exists)
    {
        DirectoryInfo di = System.IO.Directory.CreateDirectory(file);
        Console.WriteLine("The Folder is created Sucessfully");
    }
    else
    {
        Console.WriteLine("The Folder already exists");
    }
    DirectoryInfo dInfo = new DirectoryInfo(file);
    DirectorySecurity dSecurity = dInfo.GetAccessControl();
    dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
    
    dInfo.SetAccessControl(dSecurity);

}
0

There are 0 best solutions below