本文介绍了净DriveInfo()与UNC路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,

有没有办法来获取UNC路径DriveInfo实例(例如\ fors343a.ww123.somedomain.net \文件夹\ 1 \),因为例如...

  VAR driveInfo =新System.IO.DriveInfo(驱动器);
 

使用UNC路径以上时 ...引发ArgumentException(\\)或驱动器号(\C \对象必须是一个根目录(\C)。)。 >

我会怎么才能检索有关或如信息使用我将如何检查一个给定的文件夹是否位于本地驱动器或UNC路径?

解决方案

DriveInfo 构造函数的备注部分说:

我是能够使其通过映射在Windows资源管理器中的网络驱动器的工作。也就是说,我映射\服务器\共享开车Z,然后 DriveInfo(Z:\\); 给我我所期待的。

不幸的是,有没有简单的方法映射从C#网络驱动器。你要么必须执行一个外部命令(即净使用Z:\服务器\共享),或调用Windows的 API函数来做到这一点。无论哪种方式你去,你将需要删除驱动器映射时,你就大功告成了。

Good morning,

is there a way to get a DriveInfo instance for UNC paths (e.g. "\fors343a.ww123.somedomain.net\folder\1\") because for example...

var driveInfo = new System.IO.DriveInfo(drive);

... throws an ArgumentException ("Object must be a root directory (\"C:\\") or a drive letter (\"C\").") when using that UNC path above.

What would I use in order to retrieve information about that or e.g. how would I check whether a given folder resides on a local drive or an unc path?

解决方案

The Remarks section for the DriveInfo constructor says:

I was able to make it work by mapping a network drive in Windows Explorer. That is, I mapped "\server\share" to drive Z, and then DriveInfo("Z:\\"); gave me what I expected.

Unfortunately, there's no simple way to map a network drive from C#. You'll either have to execute an external command (i.e. "net use z: \server\share"), or call the Windows WNetAddConnection2 API function to do it. Either way you go, you'll need to remove the drive mapping when you're done.

这篇关于净DriveInfo()与UNC路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 22:25