Use Uri
/* C#: The Complete Reference by Herbert Schildt Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // Use Uri. using System; using System.Net; public class UriDemo { public static void Main() { Uri sample = new Uri("http://MySite.com/somefile.txt?SomeQuery"); Console.WriteLine("Host: " + sample.Host); Console.WriteLine("Port: " + sample.Port); Console.WriteLine("Scheme: " + sample.Scheme); Console.WriteLine("Local Path: " + sample.LocalPath); Console.WriteLine("Query: " + sample.Query); Console.WriteLine("Path and queury: " + sample.PathAndQuery); } }