SoFunction
Updated on 2025-03-04

Generate file names using GetInvalidFileNameCharts

Sometimes you need to use the string retrieved from the database to generate a file name. If this string contains unauthorized characters (\, ?, <, >, etc.), you also need to replace these characters one by one.

The code is as follows:

public static string GetValidName(string fileName)
{
    foreach (char c in ())
    {
        fileName = (c, ' ');
    }
    return fileName;
}

In the same way, you can also determine whether an invalid character is included in a string.