I want to use functions of Path class (GetDirectoryName
, GetFileName
, Combine
,etc.) with paths in URL format with slash (/).
Example of my path:
"xxx://server/folder1/folder2/file"
I tried to do the job with Path
functions and in the end just replaced the separator.
I've found that the GetDirectoryName
function does not correctly replace the slashes:
Path.GetDirectoryName(@"xxx://server/folder/file") -> @"xxx:\server\folder"
Like you see one slash is lost.
How can I cause the Path functions to use the 'alternative' separator?
Can I use another class with the same functionality?
The path refers to the exact location of a page, post, file, or other asset. It is often analogous to the underlying file structure of the website. The path resides after the hostname and is separated by “/” (forward slash).
URL stands for Uniform Resource Locator, and is used to specify addresses on the World Wide Web. A URL is the fundamental network identification for any resource connected to the web (e.g., hypertext pages, images, and sound files). The protocol specifies how information from the link is transferred.
file is a registered URI scheme (for "Host-specific file names"). So yes, file URIs are URLs.
To recap, these are the three basic elements of a website URL: The protocol – HTTP or HTTPS. The domain name (including the TLD) that identifies a site. The path leading to a specific web page.
I'm afraid GetDirectoryName
, GetFileName
, Combine
,etc. use Path.DirectorySeparatorChar in the definition and you want Path.AltDirectorySeparatorChar.
And since Path is a sealed class, I think the only way to go about is string replacement.You can replace Path.DirectorySeparatorChar
('\') with Path.AltDirectorySeparatorChar
('/') and Path.VolumeSeparatorChar
(':') with ":/"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With