I'd like to ensure that a given file name is valid, even if it means replacing or removing some characters. I'm currently doing this:
Path.GetInvalidFileNameChars ().ToList ().ForEach (x => path.Replace (x, '-'));
But as far as I can tell, this is not guaranteed to yield a valid filename. Is there any better way than performing above pre-check followed by actually try-catching to open the file?
Edit: spot the bug in above code ;)
Minor addition: I'd prefer to keep the filename as readable as possible, so using some kind of BASE64 should be avoided.