问题描述
我运行一个非常简单的程序,这是试图在同一台机器,这是使用UNC格式(如):
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来禁用所有字符串解析并发送下面的字符串 它直到文件系统。
一个.NET兼容的UNC格式将是
\\计算机名\ D $ \共享\输入
。请参阅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工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!