UNC路径不使用.NET工作? [英] UNC path does not work with .NET?

查看:182
本文介绍了UNC路径不使用.NET工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个非常简单的程序,这是试图在同一台机器,这是使用UNC格式(如http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx):

I am running a very simple program, which is trying to list files in a folder on the same machine, which is specified using UNC format(as described in http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx):


static string rootDir = @"\\?\d:\share\input";

然而,Directory.GetFiles()不起作用,引发ArgumentException(当它被抛出 - 路径是一个零长度字符串,仅包含空白或者包含一个或多个无效字符由InvalidPathChars定义的)。 Console.WriteLine命令()不显示任何信息,证实不存在无效字符在路径中。当我用我得到同样的异常 \\ UNC \ \ D:\共享\输入或 \\ UNC \?\计算机名\共享\输入或 \\?\计算机名\共享\输入。

However the Directory.GetFiles() does not work and throws an ArgumentException(which is thrown when - path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.). The Console.Writeline() does not print anything, which confirms that there are no invalid chars in the path. I get the same exception when I use "\\UNC\?\d:\share\input" or "\\UNC\?\machinename\share\input" or "\\?\machinename\share\input".

中的d:\共享\输入的确是一个共享文件夹。

The "d:\share\input" is indeed a shared folder.

有谁知道什么可能是错误的?

Does anybody know what could be wrong?

谢谢!

推荐答案

问题是, \\?\ 是一个不支持.NET窗口API约定。 ?如果您在您的链接仔细阅读 \\。\ 不表示一个UNC路径,但对于Windows API的一个特殊的约定:

The problem is that \\?\ is a windows API convention that is not supported by .NET. If you read carefully in your link \\?\ does not denote a UNC path, but is a special convention for windows API:

有关文件I / O,在 \\?\ preFIX到路径字符串告诉视窗   API来禁用所有字符串解析并发送下面的字符串   它直到文件系统。

For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system.

一个.NET兼容的UNC格式将是 \\计算机名\ D $ \共享\输入。请参阅<一href="http://stackoverflow.com/questions/6867463/is-there-a-net-api-to-return-the-equivalent-extended-path-string-of-a-given-pat">this回答获取更多信息。

A .NET compatible UNC format would be \\machinename\d$\share\input. See this answer for more info.

它不支持.NET的原因是最有可能的扩展路径约定并不适用于所有平台,因此不能保证的框架工作。

The reason it is not supported by .NET is most likely that the extended path convention is not available on all platforms and therefore cannot be guaranteed to work by the framework.

这篇关于UNC路径不使用.NET工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆