tags:

views:

1164

answers:

1

Does the .NET Framework have any methods for converting a path (e.g. "C:\whatever.txt") into a file URI (e.g. "file:///C:/whatever.txt")?

The Uri class has the reverse (from a file URI to absolute path), but nothing as far as I can find for converting to a file URI.

Also, this is NOT a ASP.NET application.

Thanks!

+14  A: 

The Uri constructor has the ability to parse full file paths and turn them into Uri style paths. So you can just do the following.

var uri = new Uri("c:\\foo");
var converted = uri.AbsoluteUri;
JaredPar
@Brian, thanks!
JaredPar
Awesome, thanks!
Tinister