当前位置: 首页 > news >正文

C#中当程序的访问权限不足时,Directory.Exists和File.Exists方法不会抛出异常报错...

有些时候,我们开发的C#应用程序的执行账号,可能没有对一些文件夹和文件的访问权限,当我们使用Directory.Exists和File.Exists方法去判断这些文件夹和文件是否存在的时候,Directory.Exists和File.Exists方法并不会抛出异常报错,这两个方法会返回false,表示查找的文件夹和文件不存在。尽管文件夹和文件实际上是存在的,只是C#程序的执行账号没有权限访问而已,但是Directory.Exists和File.Exists方法还是会返回false,并不会抛出异常报错。

 

以下是MSDN对Directory.Exists和File.Exists方法的解释,其中也提到了权限不足的问题:

Directory.Exists

Returns
true if path refers to an existing directory; false if the directory does not exist or an error occurs when trying to determine if the specified directory exists.

 

File.Exists

Returns
true if the caller has the required permissions and path contains the name of an existing file; otherwise, false. This method also returns false if path is null, an invalid path, or a zero-length string. If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.

 

 

参考链接

Directory.Exists
File.Exists

 

转载于:https://www.cnblogs.com/OpenCoder/p/10482974.html

http://www.xdnf.cn/news/813565.html

相关文章:

  • Windows server 2012R2下IIS服务器的配置与管理
  • 局域网电脑入侵
  • Linux---Shell(使用技巧 与 变量)
  • 事件对象
  • 使用SWFUpload上传文件
  • 【实用工具系列】MathCAD入门安装及快速上手使用教程
  • 如何使用五笔输入法
  • ScaleAnimation开始结束位置分析
  • Ajax:万字总结黑马笔记,学懂Ajax看这一篇就够了
  • jQuery的基本使用
  • Eclipse Android开发环境搭建
  • 域渗透—域用户枚举与口令爆破
  • 6个月Python学习计划 Day 13 - 文件操作基础
  • 如何获取显卡的GPU占用率和显存占用情况
  • 新手小白零基础,该怎样学习编程呢?零基础入门到精通,收藏这一篇就够了
  • 搜索引擎的工作原理
  • 什么是a站、b站、c站、d站、e站、f站、g站、h站、i站、j站、k站、l站、m站、n站?
  • 【python】深度学习中一个保证训练测试样本数据均衡性的重要函数:StratifiedShuffleSplit
  • 网刻工具大全:四款软件优缺评析(转)
  • 漂亮的个人主页HTML源码
  • mkdirs与createNewFile区别,Java复制文件工具类
  • 素数环
  • 微信小程序-wxml和wxss样式
  • Linux常用命令_(文件权限)
  • [笔记]vs2015 编写汇编masm32之使用MASM32库
  • 天龙八部万象归一第8版单机安装教程+GM工具+虚拟机一键端
  • Ant下载及配置安装
  • 这回,数据库事务4种隔离级别及7种传播行为,终于说明清楚了
  • 机器学习实战(入门级) ------ Kaggle 泰坦尼克号幸存者预测 (随机森林,KNN,SVM)
  • 因 Cannot resolve com.lowagie:itext:2.1.7.js6,选择手动安装 Jar 包进 Maven 仓库