惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
B
Blog
N
Netflix TechBlog - Medium
量子位
月光博客
月光博客
博客园_首页
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
M
MIT News - Artificial intelligence
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
腾讯CDC
Engineering at Meta
Engineering at Meta
云风的 BLOG
云风的 BLOG
L
LangChain Blog
GbyAI
GbyAI
IT之家
IT之家
Y
Y Combinator Blog
人人都是产品经理
人人都是产品经理

博客园 - See Me Fly

[MVC] Code First中Migration的问题 [MVC]开篇 搭建小型邮件服务器 Visual Studio中添加Service异常 IIS7 IIS8上面运行 ASP 画圆滑的曲线连接地图上面的点 [IIS] 不能加载类型System.ServiceModel.Activation.HttpModule [DICOM] Download ClearCanvas Source Code [DICOM] 开篇 研究SplendidCRM [转]C#WinForm - 立即更新静态文本Label Crystal Report 2011连接SQL Server 2008失败 Xcode: 给项目添加framework DC中用户的同步问题 用VNC连接Mac OS Xcode访问SVN服务器 Window 7访问共享目录问题 JIRA配置SSL Failed to install MSXML6 when installing SQL Server 2005 - See Me Fly
UnauthorizedAccessException trying to delete a file
See Me Fly · 2012-08-18 · via 博客园 - See Me Fly

最近写了一段代码,将本地文件上传到共享目录(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);