Replacing from a list chars in a string
foreach(var c in Path.GetInvalidPathChars())
    path = path.replace(c, '_')


That's a bit inefficient as it can allocate a string on every itteration, but usually not a problem. Alternative:

var chars = Path.GetInvalidPathChars()
path = new string(path.Select(c =&gt; chars.Contains(c) ? '_' : c).ToArray())