Skip to content

How can I lock a folder in c#?

Abdullah AKALIN

Abdullah AKALIN

Asked Aug 12, 2010, 6:24 AM EDT3 answers
Share
LinkedInX
Hi.I want to lock my folder with c#? How can I do it?

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0
    Not sure what you mean by lock a folder.  Do you want to hide a folder in the file system?  Make it read-only?  Prevent permission access for a particular group?
    0
  • Mike Gold
    0
    You can set the Attributes on a file using DirectoryInfo
    http://msdn.microsoft.com/en-us/library/system.io.directoryinfo_properties.aspx
     
    DirectoryInfo directoryInfo = new DirectoryInfo(@"c:\temptest");
    directoryInfo.Attributes = directoryInfo.Attributes | FileAttributes.ReadOnly;
    Unfortunately this won't really do much, because there is not much meaning to setting a directory to readonly.  You more likely want to limit write access to a user or group of users through Active Directory.  Below is a link on codeproject that tells you how to do almost anything you can think of to restricting permissions to a directory:
    http://www.codeproject.com/KB/system/everythingInAD.aspx
     
     
     
    0
  • 1 short reply
    • Abdullah AKALIN
      0
      I mean make it read-only.
      0