In .NET 4.0, whats the equivalent function to IO.Path.GetFileName for urls?
You may stick to creating Uri object or if you care about performance use something similar to this one:
public class UriHelpers
{
public static string GetFileNameFromUrl(string url)
{
string lastSegment = url.Split('/').Last();
return lastSegment.Substring(0, lastSegment.IndexOf('?') < 0 ? lastSegment.Length : lastSegment.IndexOf('?'));
}
}
You can use Server.MapPath() to map a physical path from a virtual path.
Additionally, there are a number of methods within the HTTPUtility that will help you map various different types of path.
There are many ways, the main being described here
Baqsically exploiting the Uri class, and maybe string tokeniztion if needed.
The Uri class is your friend.
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.
IsFile will try to determine if the Uri does indeed point to a file.
Use the Segements property in order to get the file name (it will be the last segment).
Uri uri = new Uri("http://example.com/title/index.htm");
var filename = uri.Segments[uri.Segments.Length - 1];
// filename == "index.htm"