What's the equivalent of Path.GetDirectory()...

  • Thread starter Thread starter mick
  • Start date Start date
...for a web address.

Given
http://podcasts.mysite.com/podcasts/latest/latestepisode.mp3

how do I get
http://podcasts.mysite.com/podcasts/latest/

I actually tried using Path.GetDirectory() but ended up with

http:\\podcasts.mysite.com\\podcasts\\latest\\

This is for a C# WPF app.

I don't think there is anything builtin for this as URL's are
fundamentally not files.

What would you expect from:

http://podcasts.mysite.com/podcasts/latest/latestepisode.mp3/foo/bar?id-123

?

:-)

So LastIndexOf seems as good or as bad as any other solution.

Arne
 
I don't think there is anything builtin for this as URL's are
fundamentally not files.

What would you expect from:

http://podcasts.mysite.com/podcasts/latest/latestepisode.mp3/foo/bar?id-123

?

To be honest I don't know anything about webby stuff so I don't know what to
expect:-)
I just assumed (hoped) there would be something similar in the web part of the
API.
:-)

So LastIndexOf seems as good or as bad as any other solution.

Okidoke, thanks for your reply.

mick
 
To be honest I don't know anything about webby stuff so I don't know
what to expect:-)
I just assumed (hoped) there would be something similar in the web part
of the API.

Full file names can be decomposed in:

drive (or host name for UNC)
directory
simple file name

URL's can be decomposed in:

protocol
optional username and password
host name
optional port number
path
optional query

Simply different.

..NET do have classes and methods to decompose a URL.

Arne
 
UriBuilder class might help - it will at least split the URI parts

The Uri also have some basic methods.

But that does not help much if the problem is not well defined.

Arne
 
Back
Top