According to RFC 3986 the valid characters for the path component are:
a-z A-Z 0-9 . - _ ~ ! $ & ' ( ) * + , ; = : @
as well as percent-encoded characters and of course, the slash /
.
I can however not find a class that converts a string to well formatted path according to above rules.
string rawPath = "/A9_(+@*)/# ?/";
string expectedPath = "/A9_(+@*)/%23%20%3f";
However, see code below:
string rawPath = "/A9_(+@*)/# ?/";
Uri.EscapeDataString(rawPath); //Output=>%2FA9_%28%2B%40%2A%29%2F%23%20%3F%2F
Uri.EscapeUriString(rawPath); //Ouput=>/A9_(+@*)/#%20?/
HttpUtility.UrlPathEncode(rawPath); //Ouput=>/A9_(+@*)/#%20?/
Nothing I tried leaves allowed characters unescaped and propery escapes all other characters.
Hopefully somebody can save me from having to write my own utility!