views:

1180

answers:

3

I keep getting this error.

Invalid URI: The format of the URI could not be determined.

the code I have is:

Uri uri = new Uri(slct.Text);
if (DeleteFileOnServer(uri))
{
    nn.BalloonTipText = slct.Text + " has been deleted.";
    nn.ShowBalloonTip(30);
}

EDIT: the content in slct.Text is ftp.jt-software.net/style.css.

What gives? How is that not a valid URI format? It's plain text.

+4  A: 

Check possible reasons here: http://msdn.microsoft.com/en-us/library/z6c2z492(v=VS.100).aspx

EDIT:

You need to put the protocol prefix in front the address, i.e. in your case "ftp://"

Simon
Why did you downvote? ... Is there something wrong?
Simon
Nothing wrong at all. I was doing everything really quickly, and I accidently clicked the down button, and it said that unless the question is edited i cannot undo it, so if you could kindly edit your question or something, i can re-upvote you :) So sorry about that :-( I didn't mean to downvote you
lucifer
hehe, np... I added a space... ;)
Simon
@j-t-s: You can now upvote... would be kind :D
Simon
voting up back instead of j-t-s. Since the latter disappeared :)
Andy
@Andy: thank you :)
Simon
+1 more devoted upvote in absense of @j-t-s ;-)
Abel
@Simon, I just voted you UP again, sorry about the HUGE delay! You can punch me 2times lol
lucifer
+2  A: 

Sounds like it might be a realative uri. I ran into this problem when doing cross-browser Silverlight; on my blog I mentioned a workaround: pass a "context" uri as the first parameter.

If the uri is realtive, the context uri is used to create a full uri. If the uri is absolute, then the context uri is ignored.

EDIT: You need a "scheme" in the uri, e.g., "ftp://" or "http://"

Stephen Cleary
+1  A: 

It may help to use a different constructor for Uri.

If you have the server name

string server = "http://www.myserver.com";

and have a relative Uri path to append to it, e.g.

string relativePath = "sites/files/images/picture.png"

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);
CJBrew