private void UnsetReadOnly(string dirPath)
{//http://bbs.csdn.net/topics/380233913
string[] dirPathes = Directory.GetDirectories(dirPath, "*.*", SearchOption.AllDirectories);
string[] filePathes = Directory.GetFiles(dirPath, "*.*", SearchOption.AllDirectories);
foreach (var dp in dirPathes)
{
DirectoryInfo dir = new DirectoryInfo(dirPath);
dir.Attributes = FileAttributes.Normal & FileAttributes.Directory;
}
foreach (var fp in filePathes)
{
File.SetAttributes(fp, System.IO.FileAttributes.Normal);
}
}

 

用ICSharpZipLib解压,如果目标文件夹里的文件为只读属性会导致解压失败:UnauthorizedAccessException: Access to the path is denied.

使用如上代码取消文件的只读属性后解决.(只设置文件夹的Attributes为非只读没作用,里面的文件还是只读)

 

From:http://www.cnblogs.com/xuejianxiyang/p/7514477.html

相关文章:

  • 2022-12-23
  • 2022-01-20
  • 2021-11-27
  • 2021-06-06
  • 2021-10-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2021-11-27
  • 2021-09-24
  • 2021-12-01
相关资源
相似解决方案