[ACCEPTED]-c# type to handle relative and absolute URI's and local file paths-uri
Accepted answer
Using the Uri class, it seems to be working. It 6 turns any file path to the `file:///..." syntax 5 in the Uri. It handles any URI as expected, and 4 it has capacity to deal with relative URIs. It 3 depends on what else you are trying to do 2 with that path.
(Updated to show the use 1 of relative Uri's):
string fileName = @"c:\temp\myfile.bmp";
string relativeFile = @".\woohoo\temp.bmp";
string addressName = @"http://www.google.com/blahblah.html";
Uri uriFile = new Uri(fileName);
Uri uriRelative = new Uri(uriFile, relativeFile);
Uri uriAddress = new Uri(addressName);
Console.WriteLine(uriFile.ToString());
Console.WriteLine(uriRelative.ToString());
Console.WriteLine(uriAddress.ToString());
Gives me this output:
file:///c:/temp/myfile.bmp
file:///c:/temp/woohoo/temp.bmp
http://www.google.com/blahblah.html
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.