Best way to make a file writeable in c#

Two ways:

System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
fileInfo.IsReadOnly = true/false;

or

// Careful! This will clear other file flags e.g. `FileAttributes.Hidden`
File.SetAttributes(filePath, FileAttributes.ReadOnly/FileAttributes.Normal);

The IsReadOnly property on FileInfo essentially does the bit-flipping you would have to do manually in the second method.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)