问题描述
如何获取一个路径下文件的读写权限?要代码谢谢
解决方案
解决方案二:
一个目录下的文件可能权限多不一样的DirectoryInfodirInfo=newDirectoryInfo("D:\");foreach(FileInfofInfoindirInfo.GetFiles()){boolisReadOnly=fInfo.IsReadOnly;}
解决方案三:
不是我主要是想获取一下这个文件夹的读写权限,不是文件的请问该怎么写
解决方案四:
没弄过
解决方案五:
DirectoryInfodi=newDirectoryInfo(sPath);if(di.Attributes==FileAttributes.ReadOnly){....}
解决方案六:
privateboolSetGetPathListDemo(){try{Console.WriteLine("********************************************************n");FileIOPermissionfileIOPerm1;Console.WriteLine("CreatingaFileIOPermissionwithAllAccessrightsfor'C:\Examples\Test\TestFile.txt");fileIOPerm1=newFileIOPermission(FileIOPermissionAccess.AllAccess,"C:\Examples\Test\TestFile.txt");Console.WriteLine("Adding'C:\Temp'tothewriteaccesslist,andn'C:\Examples\Test'toreadaccess.");fileIOPerm1.AddPathList(FileIOPermissionAccess.Write,"C:\Temp");fileIOPerm1.AddPathList(FileIOPermissionAccess.Read,"C:\Examples\Test");string[]paths=fileIOPerm1.GetPathList(FileIOPermissionAccess.Read);Console.WriteLine("ReadaccessbeforeSetPathList=");foreach(stringpathinpaths){Console.WriteLine("t"+path);}Console.WriteLine("Settingthereadaccesslistton'C:\Temp'");fileIOPerm1.SetPathList(FileIOPermissionAccess.Read,"C:\Temp");paths=fileIOPerm1.GetPathList(FileIOPermissionAccess.Read);Console.WriteLine("ReadaccesslistafterSetPathList=");foreach(stringpathinpaths){Console.WriteLine("t"+path);}paths=fileIOPerm1.GetPathList(FileIOPermissionAccess.Write);Console.WriteLine("WriteaccesslistafterSetPathList=");foreach(stringpathinpaths){Console.WriteLine("t"+path);}Console.WriteLine("Writeaccess=n"+fileIOPerm1.GetPathList(FileIOPermissionAccess.AllAccess));}catch(ArgumentExceptione){//FileIOPermissionAccess.AllAccesscannotbeusedasaparameterforGetPathList.Console.WriteLine("AnArgumentExceptionoccurredasaresultofusingAllAccess."+"ThispropertycannotbeusedasaparameterinGetPathList"+"becauseitrepresentsmorethanonetypeoffilevariableaccess.:n"+e);}returntrue;}