星期五, 7月 27, 2007

常見檔案、目錄操作

  • 不錯的整理:http://silenceangelwaitingfor.spaces.live.com/blog/cns!47F284FC052C0DE0!442.entry
  • 檢驗帳號是否對某個檔案有NTFS存取權限:
    這個問題似乎沒有好的解答
    https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1851064&SiteID=1

    也許從這篇可以得到解答: http://www.codeproject.com/csharp/accessctrl3.asp?df=100&forumid=180919&exp=0&select=1350552#Accesscheck
  • 存取檔案、目錄ACL
    FileSecurity fSecurity = File.GetAccessControl(@"c:\temp");
    fSecurity.AddAccessRule(
    new FileSystemAccessRule(
    "DomainA/UserB",
    FileSystemRights.AppendData | FileSystemRights.CreateFiles,
    AccessControlType.Allow)
    );
    File.SetAccessControl(@"c:\temp", fSecurity);
  • 設定檔案成ReadOnly
    FileInfo f = new FileInfo(@"c:\temp\1.txt");
    f.Attributes |= FileAttributes.ReadOnly;