项目中有个IO操作,遇到过了这个问题,网上很多的说什么ASP.NET 账户权限的问题,APP.CONFIG 配置文件要添加代码等乱七八糟的一堆问题,
经过分析和认真总结写了以下静态方法Fixed it.
public static void FileCopy(string readPath, string savePath, bool overWrite)
{
if (File.Exists(readPath))
{
if (File.Exists(savePath))
{
FileInfo fi = new FileInfo(savePath);
if (fi.Attributes == FileAttributes.ReadOnly)
{
fi.Attributes = FileAttributes.Normal;
}
File.Delete(savePath);
}
File.Copy(readPath, savePath, overWrite);
}
}