Setzt oder entfernt den Schreibschutz einer Datei.
benötigte Namespaces:
System.IO
/// <summary>
/// Sets the read only attribute.
/// </summary>
/// <param name="fullName">The full name.</param>
/// <param name="readOnly">if set to <c>true</c> [read only].</param>
private static void SetReadOnlyAttribute(string fullName, bool readOnly)
{
FileInfo filePath = new FileInfo(fullName);
FileAttributes attribute;
if (readOnly)
attribute = filePath.Attributes | FileAttributes.ReadOnly;
else
attribute = (FileAttributes) (filePath.Attributes - FileAttributes.ReadOnly);
File.SetAttributes(filePath.FullName, attribute);
}
3 Kommentare zum Snippet