Firstly, it is worth noting that "." it is completely legal in file names, but "/" is not, therefore, as long as the example you provided does not require translation, "www.ibm.com/path1/file1.jpg" will be.
A simple string.Replace would be the best solution here - if you find that a character that is legal in the file name but illegal in the URL.
Assuming the illegal URL is βΒ§β (which may be legitimate at the URL), you have received:
string.Replace("/", "Β§");
to translate to a file name and:
string.Replace("Β§", "/");
to translate back.
This URL-encoded page defines valid, invalid, and insecure (valid, but with a special meaning) characters for URLS. The characters in the "upper half" of the ISO-Latin set of 80-FF hex (128-255 decimal numbers) are not legal, but may be in order in the file names.
You will need to do this for each character in the URL that is in the set of invalid file names. You can get this using GetInvalidFileNameChars .
UPDATE
Assuming you cannot find matching character pairs, then another solution would be to use a lookup table. One column contains the URL of another generated file name. As long as the generated name is unique (the GUID will do), you can do a two-way search to go from one to the other.
source share