为什么 IsWellFormedOriginalString 在文件 Uris 上失败?
我有这样的代码:
string uriString = @"C:\Temp\test.html";
Uri uri = new Uri(uriString);
bool goodCond = uri.IsWellFormedOriginalString();
但是 goodCond 是假的!我做错了什么?
编辑: 谢谢约翰内斯和卡特德。我将重点关注我的问题:如何将有效文件路径转换为有效文件 Uri(使用 uri.IsWellFormedOriginalString 作为 Uri 有效性的指示)? 看看这个:
DirectoryInfo di = new DirectoryInfo(@"c:\temp");
FileInfo [] fis = di.GetFiles("test.html");
FileInfo fi = fis[0];
string uriString = fi.FullName;
Uri uri = new Uri(uriString);
bool goodCond = uri.IsWellFormedOriginalString()
显然 fi.fullName 是一个格式良好的路径,但仍然是 goodCond 是坏的!
I have code like this:
string uriString = @"C:\Temp\test.html";
Uri uri = new Uri(uriString);
bool goodCond = uri.IsWellFormedOriginalString();
But goodCond is false! What am I doing wrong?
Edit:
Thanks Johannes and Catdirt. I'll focus my question: How do I convert a valid file path to a valid file Uri (using uri.IsWellFormedOriginalString as an indication to the validity of the Uri)?
Take a look at this:
DirectoryInfo di = new DirectoryInfo(@"c:\temp");
FileInfo [] fis = di.GetFiles("test.html");
FileInfo fi = fis[0];
string uriString = fi.FullName;
Uri uri = new Uri(uriString);
bool goodCond = uri.IsWellFormedOriginalString()
Obviosly fi.fullName is a well formed path, but still goodCond is bad!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 URI 格式不正确。
一个格式良好的示例是
file:///C:/Temp/test.html
。Your URI is not well-formed.
A well-formed example would be
file:///C:/Temp/test.html
.这是错误的,因为它的格式不正确。
http://msdn.microsoft.com/en-us/库/system.uri.iswellformedoriginalstring.aspx
It's false because it's not well formed.
http://msdn.microsoft.com/en-us/library/system.uri.iswellformedoriginalstring.aspx