#region文件或文件夹去除只读属性
stringpath=@"C:\123.txt";
DirectoryInfodirInfo=newDirectoryInfo(path);
dirInfo.Attributes=FileAttributes.Normal|FileAttributes.Directory;
FileInfofileInfo=newFileInfo(path);
try
{
if(fileInfo.IsReadOnly)
{
File.SetAttributes(path,FileAttributes.Normal);
}
FileStreamfs=newFileStream(path,FileMode.Append,FileAccess.Write);
StreamWritersw=newStreamWriter(fs,Encoding.UTF8);
sw.WriteLine("AAA");
sw.Close();
fs.Close();
//fileInfo.Delete();
}
catch(System.Exceptionex)
{
Console.WriteLine(ex.ToString());
Console.ReadKey();
}
finally
{
}
Console.WriteLine("文件修改成功!");
Console.ReadKey();
#endregion
如果觉得《服务器文件夹只读属性去不掉 C# 去除文件或 文件夹只读属性》对你有帮助,请点赞、收藏,并留下你的观点哦!