软件下载 | 资讯教程 | 最近更新 | 下载排行 | 一键转帖 | 发布投稿
您的位置:最火下载站 > 电脑教程 > 系统相关 > Win7创建FileStream提示UnauthorizedAccessException的错误

Win7创建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 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.

    相关阅读
    栏目导航
    推荐软件