Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Reverse UrlPathEncode

Tags:

c#

url

I have this:

file://localhost/Volumes/Untitled%20RAID%20Set%201/Callum/iTunes/Music/Steppenwolf/Steppenwolf_%20Gold/1-09%20Magic%20Carpet%20Ride.mp3

It is a location on Mac, its path has been encoded for use in an XML file.

To make this path you can use UrlPathEncode.

But now, I want to put that back to its normal readable path i.e. minus %20 and other characters that are replaced such as acute "e" etc etc etc. Bar the "/" that can easily be changed to "\"

How can you do it with out writing your own "reverser"?

If it comes down to it I will, but I would rather not.

like image 553
Callum Linington Avatar asked Apr 26 '26 02:04

Callum Linington


1 Answers

You need to use the opposite of Encode which is of course, Decode.. HttpUtility.UrlDecode:

HttpUtility.UrlDecode("file://localhost/Volumes/Untitled%20RAID%20Set%201/Callum/iTunes/Music/Steppenwolf/Steppenwolf_%20Gold/1-09%20Magic%20Carpet%20Ride.mp3");

Which will return:

file://localhost/Volumes/Untitled RAID Set 1/Callum/iTunes/Music/Steppenwolf/Steppenwolf_ Gold/1-09 Magic Carpet Ride.mp3
like image 143
DGibbs Avatar answered Apr 28 '26 15:04

DGibbs