rcook349 kirjoitti:
From within my project, I am opening an file elsewhere on the network
and changing contents within.
When I go to close/save, however, I can't because it's read-only (as
it's checked in).
Can I just flip read-only off, make my changes and save it, and then
flip read only back on (programmatically)? How can I do this, please?
Thanks.
using System.IO;
if (File.Exists(fileName))
{
FileAttributes attrs = File.GetAttributes(fileName);
File.SetAttributes(fileName, attrs & ~FileAttributes.ReadOnly);
MakeTheChanges(fileName);
attrs = File.GetAttributes(fileName);
File.SetAttributes(fileName, attrs | FileAttributes.ReadOnly);
}
There is two calls to GetAttributes, since most likely your
MakeTheChanges sets at least the archive bit.
--
Arto Viitanen