I am downloading a file from web and saving it on disk. That's easy, but some web files have characters in them that are not allowed when saving the file on disk. Most notably when I download a file such as script.js?something=somethingelse
I already found this post that deals with removing the illegal characters, but I don't want to do that. I want to somehow encode the filename, so that when I load the file from disk I can decode it and I will have the original name again.
I found this page describing which characters aren't allowed, but it's kind of vague, as it mentions
Any other character that the target file system does not allow.
What I came up with so far is to use HttpUtility.UrlEncode
for this and it seems to be working alright. My fear is that it isn't 'right' and that it will fail in some scenarios. So does anyone know the "right" way of accomplishing this?