C# access to the path is denied

【原创手打,转载请说明出处】

winform 访问局域网内文件夹,而次文件夹是只有读取权限【PS:很多政府机构就是这样,要不也不会这么麻烦不是。】

而之后出现了此bug:access to the path is denied

监控代码发现

FileStream fileStream = File.Open(fileName, FileMode.Open)

这一句代码出错,是为什么呢? 一直想不明白,只能上google查资料

查了半天还是没结果,直接查Open的方法,尽然有重载,

FileAccess枚举,读,写,读写

FileStream fileStream = File.Open(fileName, FileMode.Open, FileAccess.Read)

改为只读就好了。异常处理结束。

原文地址:https://www.cnblogs.com/zhoudemo/p/2321486.html