views:

134

answers:

2

Hello,

What is the preferred way to remove the readonly attribute of a file in Compact Framework as we don't have a File::SetAttributes?

Thank you!

+2  A: 

You could use the OpenNetCF Smart Device Framework, which has a FileHelper class that implements the SetAttributes function.

Or if you don't want to go that route, you could PInvoke the native SetFileAttributes method.

tomlog
+1  A: 

This also works:

FileInfo fileInfo = new FileInfo(path);
FileAttributes attributes = fileInfo.Attributes;

if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
    // set the attributes to nonreadonly
    fileInfo.Attributes &= ~FileAttributes.ReadOnly;
}
Bryan