I am trying to create a folder from my application in the c: \ folder (for example: c \), but this folder is always created with read-only permission.
I tried the codes below, but could not change the attributes. Please help me.
Method 1
var di = new DirectoryInfo(temppath);
File.SetAttributes(temppath, FileAttributes.Normal);
File.SetAttributes(temppath, FileAttributes.Archive); */
Method 2
di.Attributes = di.Attributes | ~FileAttributes.ReadOnly;
File.SetAttributes(temppath, File.GetAttributes(temppath) & ~FileAttributes.ReadOnly);
Method 3
foreach (string fileName in System.IO.Directory.GetFiles(temppath))
{
System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
fileInfo.Attributes |= System.IO.FileAttributes.ReadOnly;
fileInfo.IsReadOnly = false;
}
all of these methods do not work or just change the attributes of the file, not the folder.
source
share