Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Getting the Everyone Local Group Account Name in C#

See how easy it is to get the "Everyone" account name, with the help of the DirectorySecurity and SecurityIdentifier classes.


advertisement

It is quite easy to get the "Everyone" account name, with the help of the DirectorySecurity and SecurityIdentifier classes. Here is a small example of getting the name and allowing the user to save a file inside a location with the correct permissions:

string PATH = "";            
if (!Directory.Exists(Path.GetFullPath(PATH)))
            {
                Directory.CreateDirectory(PATH);

                DirectorySecurity dirSec = Directory.GetAccessControl(PATH);
                SecurityIdentifier siEveryobody = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                dirSec.AddAccessRule(new FileSystemAccessRule(siEveryobody, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
                Directory.SetAccessControl(PATH, dirSec);


            }

            using (StreamWriter swWriter = new StreamWriter(PATH, true))
            {
                sw.WriteLine("TEXT");
                sw.Flush();
                sw.Close();
            }

 

Visit the DevX Tip Bank

 





   
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date