C#設(shè)置文件權(quán)限

   在開發(fā)中,我們經(jīng)常會(huì)使用IO操作,例如創(chuàng)建,刪除文件等操作。在項(xiàng)目中這樣的需求也較多,我們也會(huì)經(jīng)常對(duì)這些操作進(jìn)行編碼,但是對(duì)文件的權(quán)限進(jìn)行設(shè)置,這樣的操作可能會(huì)手動(dòng)操作,現(xiàn)在介紹一種采用代碼動(dòng)態(tài)對(duì)文件設(shè)置權(quán)限的操作。

   在對(duì)文件進(jìn)行權(quán)限設(shè)置在DOtNet中,會(huì)采用FileSystemAccessRule類進(jìn)行文件的權(quán)限操作。

    1.現(xiàn)在看一下FileSystemAccessRule的實(shí)現(xiàn)代碼:

復(fù)制代碼
  public FileSystemAccessRule(
            IdentityReference identity,
            FileSystemRights fileSystemRights,
            AccessControlType type )
            : this( identity,
                AccessMaskFromRights( fileSystemRights, type ),
                false,
                InheritanceFlags.None,
                PropagationFlags.None,
                type )
        {
        } public FileSystemAccessRule(
            String identity,
            FileSystemRights fileSystemRights,
            AccessControlType type )
            : this(
                new NTAccount(
        		

網(wǎng)友評(píng)論