c# - Filename with a hash and Uri LocalPath handling -
c# - Filename with a hash and Uri LocalPath handling -
i'm coding in c# , i've uri file (that can unc, web served, etc, that's why need utilize uri) , ran in case uri pointing file containing #
in name.
the uri interpreted fragmented 1 uri.fragment
not empty , uri.localpath
broken, points hypothetical location denoted uri hash.
#
part of filename? if not, how handle nicely because fragment in case contains farther special characters (kanjis) , gets escaped, simple string operations not sufficient.
you can utilize system.uribuilder
class.
uribuilder builder1 = new uribuilder("http://yourdomain.com/"); builder1.path = @"hello world#シンガポール国.txt"; uri url1 = builder1.uri; system.diagnostics.debug.writeline(url1.tostring()); // -> http://yourdomain.com/hello world%23シンガポール国.txt system.diagnostics.debug.writeline(url1.localpath); // -> /hello world#シンガポール国.txt
in case, fragment
property remains blank. url form of uri
escape hash character, since has special meaning in usage. localpath
property retain hash character without encoding it, since legal in context.
c# file uri special-characters
Comments
Post a Comment