0

我正在开发 WM6+ 的应用程序并尝试覆盖现有文件:

File.Copy(src, dest, true);

但我得到这个错误:

System.UnauthorizedAccessException: UnauthorizedAccessException
at System.IO.__Error.WinIOError()
at System.IO.File.InternalCopy()
at System.IO.File.Copy()

因此,我尝试更改目标文件上的文件属性以便能够覆盖它:

System.IO.File.SetAttributes(dest, FileAttributes.Normal);

但是当我尝试编译时,我得到了这个:

Error   1   'System.IO.File' does not contain a definition for 'SetAttributes'  L:\Admin\Applications_Source_Code\CommonTime_AEP_Config_Source\AEP_WM6 - Production Code\AEP_WM6\Form1.cs   133 26  AEP_WM6

为什么 SetAttributes 不存在?!

这是我要覆盖的文件(不是系统文件,只是在路径相关时显示):

@"\Program Files\Common Files\Trimble\GeoData\PFToolkit.csw"

这似乎已经成功了(感谢 TheGreatCO 的评论)将我指向这里:Remove readonly in Compact Framework

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

1 回答 1

0

这个问题的解决方案是使用 OpenNETCF 框架。例如;

OpenNETCF.IO.FileHelper.SetAttributes("filePath ise here", FileAttributes.Normal);
于 2014-09-29T13:53:12.290 回答