windows 7 下创建FileStream 时出现 UnauthorizedAccessException

[Issue]windows 7 下创建FileStream 时出现 UnauthorizedAccessException

 

[Resolution]

之前曾使用在其他盘创建一个文件夹,文件夹的security允许everyone来进行Full control,然后把文件创建在这个文件夹下面,即使是这样也仍然会出现UnauthorizedAccessException。

最后的解决方案是把文件创建在ApplicationData下面就不会出现UnauthorizedAccessException。

 StringBuilder folder = new StringBuilder(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));

 

stackoverflow网站上查了下UnauthorizedAccessException应该改是操作系统抛出来的异常,这样说来,win7 或者vista只能在ApplicationData下面创建用户自己的文件。

2 vote down check

A UnauthorizedAccessException is thrown when there is a permissions error accessing the file on disk. That is an error at the operating system level such as a normal user trying to overwrite an operating system file (like kernel32.dll).

A SecurityException is thrown if there is a security violation at the CLR level. For example if you are running as a low access ClickOnce application and attempt to read / write to a place in the file system forbidden by the CLR security settings in the process.

 

 

 

 

转载于:https://www.cnblogs.com/gracestoney/archive/2010/05/09/1727483.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值