.net中创建目录的问题(未找到路径X的一部分|Could not find a part of the path)
2009-11-11 10:41
465 查看
在.net创建目录里最多使用的就是Directory.CreateDirectory,该函数的好处是不管有多少级子目录,可以一次创建完,也就是说这个函数是从根目录开始,一层一层的判断、一层一层进行创建的。
但这样的便利也造成了一个问题,举例来说:
//Server01/Docs/Category1/是程序的一个工作目录,当前运行程序的用户只对//Server01/Docs/Category1/有访问权限,而对//Server01/Docs/目录没有访问权限,这时候我们要在//Server01/Docs/Category1/下创建一个子目录Folder1,对于这样的需求,使用Directory.CreateDirectory创建目录就会报错,因为Directory.CreateDirectory工作时无法从根目录一层层向下遍历。错误信息如下:
Could not find a part of the path "//Server01/Docs/"
或未找到路径"//Server01/Docs/"的一部分
为了绕过这个问题,可以使用Microsoft Scripting Runtime中的FileSystemObject,该组件中的CreateFolder方法与Directory.CreateDirectory的原理不同,FileSystemObject.CreateFolder只能一次创建一级目录,也就没了的多级遍历所造成的权限问题
但这样的便利也造成了一个问题,举例来说:
//Server01/Docs/Category1/是程序的一个工作目录,当前运行程序的用户只对//Server01/Docs/Category1/有访问权限,而对//Server01/Docs/目录没有访问权限,这时候我们要在//Server01/Docs/Category1/下创建一个子目录Folder1,对于这样的需求,使用Directory.CreateDirectory创建目录就会报错,因为Directory.CreateDirectory工作时无法从根目录一层层向下遍历。错误信息如下:
Could not find a part of the path "//Server01/Docs/"
或未找到路径"//Server01/Docs/"的一部分
为了绕过这个问题,可以使用Microsoft Scripting Runtime中的FileSystemObject,该组件中的CreateFolder方法与Directory.CreateDirectory的原理不同,FileSystemObject.CreateFolder只能一次创建一级目录,也就没了的多级遍历所造成的权限问题
相关文章推荐
- 【.Net码农】关于使用FileUpload控件报 Could not find a part of the path "X/1.jpg"
- 解决文件无法上传的问题,错误信息:System.IO.DirectoryNotFoundException: Could not find a part of the path.
- 用Reflector的插件Reflexil 报错: could not find a part of the path 'c:\documents and settings\ ……的解决办法
- 关于使用FileUpload控件报 Could not find a part of the path "X\1.jpg"
- Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'F:\'.
- 用webclient实现无空间上传文件错误:Could not find a part of the path .....
- DirectoryNotFoundException: Could not find a part of the path "……"
- 记录一下,关于错误提示:could not find a part of path “X:\”的解决办法
- 记录一下,关于错误提示:could not find a part of path “X:\”的解决办法
- 关于错误提示:could not find a part of path “X:\”的解决办法
- 1.storm问题总结 Could not find leader nimbus from seed hosts [localhost] Did you specify a valid list of
- 1.storm问题总结 Could not find leader nimbus from seed hosts [localhost] Did you specify a valid list of
- 1.storm问题总结 Could not find leader nimbus from seed hosts [localhost] Did you specify a valid list of
- struts2的配置之could not find action or result 问题的解决方法(struts.xml文件路径)
- 让人郁闷了好久的问题,终于解决了,之前网上也看到一些解决方法,但大多没有解决问题,所以记录下来,以供参考之用(ADO Could Not Find The Specified Provider)
- CXF中could not find matching RPC/Literal part问题处理
- gitlab 安装报错:Could not find modernizr-2.6.2 in any of the sources
- python py2exe打包matplotlib Could not find the matplotlib data files问题解决
- <综合>java virtual machine launcher 提示 could not find the main class,program will exit 问题
- could not get next sequence val+can not find the sequence 无法找到序列,序列不存在