Uri uri = new Uri("https://example.com/path/file.txt"); string scheme = uri.Scheme; // returns "https" string host = uri.Host; // returns "example.com" string path = uri.PathAndQuery; // returns "/path/file.txt"
Uri baseUri = new Uri("https://example.com/"); Uri relativeUri = new Uri("path/file.txt", UriKind.Relative); Uri absoluteUri = new Uri(baseUri, relativeUri); string urlString = absoluteUri.ToString(); // returns "https://example.com/path/file.txt"In this example, we create a base Uri object and a relative Uri object, and then use the base Uri to create an absolute Uri by resolving the relative Uri. We then use the ToString method to get the absolute URI string. The Uri class is part of the System namespace in the .NET Framework Class Library.