C# 为什么我们会收到 FileInfo 构造函数的“路径不合法”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1158293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why are we getting “The path is not of a legal form” for a FileInfo constructor?
提问by Colin Desmond
We're creating a FileInfo object in C# using the following code:
我们正在使用以下代码在 C# 中创建一个 FileInfo 对象:
if (planConfig->OrganisationsFilePath != nullptr)
{
FileInfo^ file = gcnew FileInfo(planConfig->OrganisationsFilePath);
//Do some stuff here
}
and our customers are reporting that they see an ArgumentException with “The path is not of a legal form” as the message being thrown. We cannot reproduce this and we're wondering what string you'd need to pass to the FileInfo constructor to see this error?
并且我们的客户报告说他们看到一个 ArgumentException 与“路径不符合法律形式”作为抛出的消息。我们无法重现这一点,我们想知道您需要将什么字符串传递给 FileInfo 构造函数才能看到此错误?
采纳答案by galaktor
The path probably contains invalid characters. See the MSDN documentation on FileInfo constructor.
路径可能包含无效字符。请参阅有关 FileInfo 构造函数的MSDN 文档。
ArgumentException:The file name is empty, contains only white spaces, or contains invalid characters.
ArgumentException: 文件名为空、仅包含空格或包含无效字符。