Remove readonly in Compact Framework

最后都变了- 提交于 2020-01-02 02:02:27

问题


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


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/2086939/remove-readonly-in-compact-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!