What I want to do is overwrite a read-only file. With a read/write file.
With read/write files if I use File.Open(file, FileMode.Create) then if the file exists then it is deleted and a new one is created. (Although I suspect that if it exists then it just opens the file and removes the contents, which is why it is unable to cope with files it encounters as read/write).
I have tried with different FileAccess enums, but none of them seem to help me (I keep getting a UnauthorizedAccessException).
The work around is that I just set the file as read/write before I try to File.Open and make a new file, is this the only way to do this?
Thanks
Consider the purpose of
ReadOnly. It’s to stop alterations to the file. What you’re trying to do, is alter the file (in this case by overwriting it).What I would imagine you would need to do, is set the file attribute:
Before you write to the file.