我一直收到这个错误.
无效的URI:无法确定URI的格式.
我的代码是:
Uri uri = new Uri(slct.Text);
if (DeleteFileOnServer(uri))
{
nn.BalloonTipText = slct.Text + " has been deleted.";
nn.ShowBalloonTip(30);
}
Run Code Online (Sandbox Code Playgroud)
更新: slct.Text中的内容是ftp.jt-software.net/style.css.
是什么赋予了?那怎么不是有效的URI格式?这是纯文本.
CJB*_*rew 112
为Uri使用不同的构造函数可能会有所帮助.
如果您有服务器名称
string server = "http://www.myserver.com";
Run Code Online (Sandbox Code Playgroud)
并有一个相对的Uri路径附加到它,例如
string relativePath = "sites/files/images/picture.png"
Run Code Online (Sandbox Code Playgroud)
当从这两个创建Uri时,我得到"格式无法确定"异常,除非我使用带有UriKind参数的构造函数,即
// 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);
Run Code Online (Sandbox Code Playgroud)
Sim*_*mon 56
请查看可能的原因:http://msdn.microsoft.com/en-us/library/z6c2z492(v = VS.100).aspx
编辑:
您需要将协议前缀放在地址前面,即在您的情况下"ftp://"
Ash*_*pta 12
更好用Uri.IsWellFormedUriString(string uriString, UriKind uriKind).http://msdn.microsoft.com/en-us/library/system.uri.iswellformeduristring.aspx
示例: -
if(Uri.IsWellFormedUriString(slct.Text,UriKind.Absolute))
{
Uri uri = new Uri(slct.Text);
if (DeleteFileOnServer(uri))
{
nn.BalloonTipText = slct.Text + " has been deleted.";
nn.ShowBalloonTip(30);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
我通过使用UriBuilder来解决这个问题.
UriBuilder builder = new UriBuilder(slct.Text);
if (DeleteFileOnServer(builder.Uri))
{
...
}
Run Code Online (Sandbox Code Playgroud)
小智 5
对我来说,问题是当我获得一些域名时,我有:
cloudsearch-..-..-xxx.aws.cloudsearch... [错误]
http://cloudsearch-..-..-xxx.aws.cloudsearch ... [右]
希望这对你有用:)