淺析C#創(chuàng)建文件夾實(shí)現(xiàn)實(shí)例
C#創(chuàng)建文件夾如何實(shí)現(xiàn),以及C#創(chuàng)建文件夾之后的設(shè)置權(quán)限的操作,是我們經(jīng)常會碰到的實(shí)際問題,那么如何實(shí)現(xiàn)C#創(chuàng)建文件夾以及C#創(chuàng)建文件夾之后的設(shè)置權(quán)限的操作是什么呢?讓我們看看實(shí)際的操作代碼:
C#創(chuàng)建文件夾實(shí)例演示:
- /*C#創(chuàng)建文件夾并設(shè)置權(quán)限*//*
 - 需要添加以下命名空間:
 - using System.IO;
 - using System.Security.AccessControl;
 - */
 - string sPath = Server.MapPath(文件夾名稱字符串);
 - Directory.CreateDirectory(sPath);
 - addpathPower(sPath, "ASPNET", "FullControl");
 - /*///////C#創(chuàng)建文件夾并設(shè)置權(quán)限////////////////*/
 - public void addpathPower(
 - string pathname, string username, string power)
 - {
 - DirectoryInfo dirinfo = new DirectoryInfo(pathname);
 - if ((dirinfo.Attributes & FileAttributes.ReadOnly) != 0)
 - {
 - dirinfo.Attributes = FileAttributes.Normal;
 - }
 - //C#創(chuàng)建文件夾取得訪問控制列表
 - DirectorySecurity dirsecurity = dirinfo.GetAccessControl();
 - switch (power)
 - {
 - case "FullControl":
 - dirsecurity.AddAccessRule(new FileSystemAccessRule(
 - username, FileSystemRights.FullControl,
 - InheritanceFlags.ContainerInherit,
 - PropagationFlags.InheritOnly, AccessControlType.Allow));
 - break;
 - case "ReadOnly":
 - dirsecurity.AddAccessRule(
 - new FileSystemAccessRule(username,
 - FileSystemRights.Read, AccessControlType.Allow));
 - break;
 - case "Write":
 - dirsecurity.AddAccessRule(
 - new FileSystemAccessRule(username,
 - FileSystemRights.Write, AccessControlType.Allow));
 
C#創(chuàng)建文件夾的一些具體實(shí)現(xiàn)的操作就先你介紹到這里,希望對你了解和學(xué)習(xí)C#創(chuàng)建文件夾的過程以及實(shí)現(xiàn)相關(guān)的權(quán)限設(shè)置有所幫助。
【編輯推薦】















 
 
 
 
 
 
 