开发者

Remove readonly in Compact Framework

开发者 https://www.devze.com 2022-12-16 14:42 出处:网络
What is the preferred way to remove the readonly attribute of a file in Compact Framework as we don\'t have a File::SetAttribut开发者_开发问答es?This also works:

What is the preferred way to remove the readonly attribute of a file in Compact Framework as we don't have a File::SetAttribut开发者_开发问答es?


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;
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号