Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert UNC path to 'file:///' URL in ASP.NET

I need to convert UNC paths to file:/// URLs. For example:

\\fileserver\share\dir\some file.ext --> file://///fileserver/share/dir/some%20file.ext

Is there a built-in function for this?

like image 546
Heinzi Avatar asked May 05 '10 14:05

Heinzi


People also ask

How do I convert a file path to URL?

Solution 1. There is no way to convert it, unless you are going to buy a hosting and domain using your desired domain name.

How do I find the UNC path of a file?

In Windows, if you have mapped network drives and you don't know the UNC path for them, you can start a command prompt (Start → Run → cmd.exe) and use the net use command to list your mapped drives and their UNC paths: C:\>net use New connections will be remembered.

Is a file path a URI?

In your thread reference someone writes 'A file path is not a URL or URI unless you put the file:// prefix on it.


1 Answers

Yes, use the Uri class in the System namespace:

Uri uri = new Uri(@"\\fileserver\share\dir\some file.ext");
string url = uri.AbsoluteUri;
like image 197
Jon Benedicto Avatar answered Sep 24 '22 07:09

Jon Benedicto