But*_*ers 2 c# attributes file readonly
如果用户不是管理员,有没有办法删除文件的只读属性?
如果您是管理员,这可行,但如果您不是,那该怎么办?
FileInfo myFile = new FileInfo(pathToFile);
myFile.IsReadOnly = false;
Run Code Online (Sandbox Code Playgroud)
您需要具有该文件的读/写权限.
我最好使用这样的方法:
FileSystemInfo fsi = new FileSystemInfo(pathToFile);
fsi.Attributes = FileAttributes.Normal;
Run Code Online (Sandbox Code Playgroud)
要么
File.SetAttributes(pathToFile, FileAttributes.Normal);
Run Code Online (Sandbox Code Playgroud)
但正如我所说,如果没有特定文件的读/写权限,这是不可能的.