How to create correctly escaped file:// URI in C#?
c#, uri
Solution
it is already encoded
uri.AbsolutePath should give you `"C:/Data/Input%20Document.txt"`
Problem
What would be the correct way to create a fully URL-encoded `file://` URI from a local path, i.e. where all special characters such as blanks etc are escaped? Given the following input ``` C:\Data\Input Document.txt ``` I would like to get ``` file:///C:/Data/Input%20Document.txt ``` I've been using ``` Uri uri = new Uri(@"C:\Data\Input Document.txt", UriKind.RelativeOrAbsolute); ``` However, this results in an unescaped URI: ``` file:///C:/Data/Input Document.txt ```