سلام ؛
از متد استاتیک GetAttributes کلاس File می تونی استفاده کنی :
string path = @"c:\temp\MyTest.txt";
// Create the file if it exists.
if (!File.Exists(path))
{
File.Create(path);
}
FileAttributes attributes = File.GetAttributes(path);
if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
// Make the file RW
attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
File.SetAttributes(path, attributes);
//now the file is not read only !
}
private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
{
return attributes & ~attributesToRemove;
}
البته از کلاس FileInfo و خاصیت IsReadOnly اون هم می تونید استفاده کنید :
FileInfo fileInfo = new FileInfo("c:\personel.txt");
fileInfo.IsReadOnly = false;