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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 09:36:29  来源:igfitidea点击:

Why are we getting “The path is not of a legal form” for a FileInfo constructor?

c#fileinfo

提问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: 文件名为空、仅包含空格或包含无效字符。