无效的 URI:无法确定 URI 的格式 [英] Invalid URI: The format of the URI could not be determined
本文介绍了无效的 URI:无法确定 URI 的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不断收到此错误.
无效的 URI:无法确定 URI 的格式.
Invalid URI: The format of the URI could not be determined.
我的代码是:
Uri uri = new Uri(slct.Text);
if (DeleteFileOnServer(uri))
{
nn.BalloonTipText = slct.Text + " has been deleted.";
nn.ShowBalloonTip(30);
}
更新:slct.Text中的内容为ftp.jt-software.net/style.css
.
Update: the content in slct.Text is ftp.jt-software.net/style.css
.
什么给?这怎么不是一个有效的 URI 格式?这是纯文本.
What gives? How is that not a valid URI format? It's plain text.
推荐答案
为 Uri 使用不同的构造函数可能会有所帮助.
It may help to use a different constructor for Uri.
如果你有服务器名称
string server = "http://www.myserver.com";
并有一个相对的 Uri 路径来附加到它,例如
and have a relative Uri path to append to it, e.g.
string relativePath = "sites/files/images/picture.png"
当从这两个创建 Uri 时,我得到无法确定格式"异常,除非我使用带有 UriKind 参数的构造函数,即
When creating a Uri from these two I get the "format could not be determined" exception unless I use the constructor with the UriKind argument, i.e.
// this works, because the protocol is included in the string
Uri serverUri = new Uri(server);
// needs UriKind arg, or UriFormatException is thrown
Uri relativeUri = new Uri(relativePath, UriKind.Relative);
// Uri(Uri, Uri) is the preferred constructor in this case
Uri fullUri = new Uri(serverUri, relativeUri);
这篇关于无效的 URI:无法确定 URI 的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文