Not all possible characters are suitable for file names. For example path separators cannot be used for file names.
This changes any string into a valid file name by replacing the invalid characters with an underscore:
public static string GetValidFileName(string fileName) { foreach (char c in Path.GetInvalidFileNameChars()) { fileName = fileName.Replace(c, '_'); } return fileName; }