FileInfo.Delete()时,没有权限,提示“无法删除,拒绝访问...”
代码如下:
using System.IO; string path_old = "E:\2010.pdf"; FileInfo fi_old = new FileInfo(path_old); fi_old.Delete();
执行抛出异常,查看了下文件属性,发现pdf文档是只读的,然后修改代码如下:
string path_old = "E:\2010.pdf";
string path_new = "E:\2012.pdf";
//给pdf文档加水印(见 http://blog.csdn.net/shouhou_bingo/article/details/52371639 )
PDFSetWaterMark.setWatermark(path_old, path_new, "XX大学");
//删除旧文件 重命名新文件
FileInfo fi_old = new FileInfo(path_old);
if ((fi_old.Attributes & FileAttributes.ReadOnly) > 0)
{
fi_old.Attributes ^= FileAttributes.ReadOnly; // 必须去除只读属性才能进行设置
}
fi_old.Delete();
FileInfo fi_new = new FileInfo(path_new);
fi_new.MoveTo(path_old);
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了
