我们可以使用 System.IO.File 类的 SetAttributes 方法为一个文件设置相关的属性,如:

在ASP.NET去掉文件的只读属性// 为文件加上一个只读的属性
在ASP.NET去掉文件的只读属性
FileAttributes attrs = File.GetAttributes("c:\\a.txt");
在ASP.NET去掉文件的只读属性File.SetAttributes(
"c:\\a.txt", attrs | FileAttributes.ReadOnly);

怎么把这个只读属性去掉呢?

在ASP.NET去掉文件的只读属性// 先把文件的属性读取出来
在ASP.NET去掉文件的只读属性
FileAttributes attrs = File.GetAttributes("c:\\a.txt");
在ASP.NET去掉文件的只读属性
在ASP.NET去掉文件的只读属性
// 下面表达式中的 1 是 FileAttributes.ReadOnly 的值
   // 此表达式是把 ReadOnly 所在的位改成 0,
在ASP.NET去掉文件的只读属性
attrs = (FileAttributes)((int)attrs & ~(1));
在ASP.NET去掉文件的只读属性
在ASP.NET去掉文件的只读属性File.SetAttributes(
"c:\\a.txt", attrs);

相关文章:

  • 2021-11-27
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
  • 2021-09-25
  • 2022-12-23
  • 2021-07-07
猜你喜欢
  • 2021-07-23
  • 2021-11-27
  • 2022-12-23
  • 2021-12-14
  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
相关资源
相似解决方案