UnauthorizedAccessException trying to delete a file
最近写了一段代码,将本地文件上传到共享目录(Shared Folder)。当想覆盖已上传的文件(先删除,后创建),系统抛出异常:UnauthorizedAccessException。确认访问共享文件夹的用户具有读取、新增、删除的权限。 原因: http://www.codeproject.com/Tips/142991/Unauthorized-Access-Exception-when-trying-to-dele "If you have created a folder via code, then folder 's readonly attributes gets setup. " 通过代码创建的文件夹、文件,默认是只读属性的。所以删除的时候会出错。 解决办法: 先把只读属性去掉。 File.SetAttributes(f.FullName, FileAttributes.Normal); 转载于:https://www.cnblogs.com/SeeMeFly/archive/2012/08/18/2645657.html 来源: https://blog.csdn.net/weixin_30680385/article/details/99158392